|
本帖最后由 showstone 于 2014-6-5 11:08 编辑
刚开始用selenium,用到wait_for_page_to_load这个函数时,每次都会报timeout错误,找了半天也不知道原因是什么,请高手指教,不胜感激。
我的环境是:ubuntu 14.04 lts, firefox 29,开发语言python 2.7,以下是异常信息:- E
- ======================================================================
- ERROR: test_new (__main__.NewTest)
- ----------------------------------------------------------------------
- Traceback (most recent call last):
- File "baidu.py", line 16, in test_new
- sel.wait_for_page_to_load("60000")
- File "/usr/local/lib/python2.7/dist-packages/selenium/selenium.py", line 1759, in wait_for_page_to_load
- self.do_command("waitForPageToLoad", [timeout,])
- File "/usr/local/lib/python2.7/dist-packages/selenium/selenium.py", line 222, in do_command
- response = conn.getresponse()
- File "/usr/lib/python2.7/httplib.py", line 1045, in getresponse
- response.begin()
- File "/usr/lib/python2.7/httplib.py", line 409, in begin
- version, status, reason = self._read_status()
- File "/usr/lib/python2.7/httplib.py", line 365, in _read_status
- line = self.fp.readline(_MAXLINE + 1)
- File "/usr/lib/python2.7/socket.py", line 476, in readline
- data = self._sock.recv(self._rbufsize)
- timeout: timed out
- ----------------------------------------------------------------------
- Ran 1 test in 44.099s
复制代码 以下是测试代码:- from selenium import selenium
- import unittest, time, re
- class NewTest(unittest.TestCase):
- def setUp(self):
- self.verificationErrors = []
- self.selenium = selenium("localhost", 4444, "*firefox",
- "http://www.baidu.com/")
- self.selenium.start()
- def test_new(self):
- sel = self.selenium
- sel.open("/")
- sel.type("id=kw1", "selenium rc")
- sel.click("id=su1")
- sel.wait_for_page_to_load("60000")
- self.failUnless(sel.is_text_present("Results * for selenium rc"))
- def tearDown(self):
- self.selenium.stop()
- self.assertEqual([], self.verificationErrors)
- if __name__ == '__main__':
- unittest.main()
复制代码 |
|