51Testing软件测试论坛

标题: selenium下的wait_for_page_to_load函数总是失败 [打印本页]

作者: showstone    时间: 2014-6-4 00:57
标题: selenium下的wait_for_page_to_load函数总是失败
本帖最后由 showstone 于 2014-6-5 11:08 编辑

刚开始用selenium,用到wait_for_page_to_load这个函数时,每次都会报timeout错误,找了半天也不知道原因是什么,请高手指教,不胜感激。

      我的环境是:ubuntu 14.04 lts, firefox 29,开发语言python 2.7,以下是异常信息:
  1. E
  2. ======================================================================
  3. ERROR: test_new (__main__.NewTest)
  4. ----------------------------------------------------------------------
  5. Traceback (most recent call last):
  6.   File "baidu.py", line 16, in test_new
  7.     sel.wait_for_page_to_load("60000")
  8.   File "/usr/local/lib/python2.7/dist-packages/selenium/selenium.py", line 1759, in wait_for_page_to_load
  9.     self.do_command("waitForPageToLoad", [timeout,])
  10.   File "/usr/local/lib/python2.7/dist-packages/selenium/selenium.py", line 222, in do_command
  11.     response = conn.getresponse()
  12.   File "/usr/lib/python2.7/httplib.py", line 1045, in getresponse
  13.     response.begin()
  14.   File "/usr/lib/python2.7/httplib.py", line 409, in begin
  15.     version, status, reason = self._read_status()
  16.   File "/usr/lib/python2.7/httplib.py", line 365, in _read_status
  17.     line = self.fp.readline(_MAXLINE + 1)
  18.   File "/usr/lib/python2.7/socket.py", line 476, in readline
  19.     data = self._sock.recv(self._rbufsize)
  20. timeout: timed out

  21. ----------------------------------------------------------------------
  22. Ran 1 test in 44.099s
复制代码
以下是测试代码:
  1. from selenium import selenium
  2. import unittest, time, re

  3. class NewTest(unittest.TestCase):
  4.     def setUp(self):
  5.         self.verificationErrors = []
  6.         self.selenium = selenium("localhost", 4444, "*firefox",
  7.                 "http://www.baidu.com/")
  8.         self.selenium.start()

  9.     def test_new(self):
  10.         sel = self.selenium
  11.         sel.open("/")
  12.         sel.type("id=kw1", "selenium rc")
  13.         sel.click("id=su1")
  14.         sel.wait_for_page_to_load("60000")
  15.         self.failUnless(sel.is_text_present("Results * for selenium rc"))

  16.     def tearDown(self):
  17.         self.selenium.stop()
  18.         self.assertEqual([], self.verificationErrors)

  19. if __name__ == '__main__':
  20.     unittest.main()
复制代码

作者: larryrelax    时间: 2014-6-4 15:50
我擦,你是问问题的吗?还要别人购买




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2