我刚刚第一次安装了 Selenium,但开始时遇到了麻烦。
安装顺利pip
:
pip install selenium
我可以import selenium
在 Python 中。
现在我正在尝试运行以下示例脚本:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
发生的情况是 Firefox 打开,但它没有导航到“ http://www.python.org ”(类似于这个问题中描述的行为- 它只显示一个空白页面)
大约 60 秒内没有任何反应,直到出现以下异常:
Traceback (most recent call last):
File "selenium-test.py", line 4, in <module>
driver = webdriver.Firefox()
File "/home/usr1/.local/lib/python2.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 61, in __init__
desired_capabilities=capabilities)
File "/home/usr1/.local/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 72, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/home/usr1/.local/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 114, in start_session
'desiredCapabilities': desired_capabilities,
File "/home/usr1/.local/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py", line 165, in execute
self.error_handler.check_response(response)
File "/home/usr1/.local/lib/python2.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 136, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: u'<HTML><HEAD>\r\n<TITLE>Network Error</TITLE>\r\n</HEAD>\r\n<BODY>\r\n<FONT face="Helvetica">\r\n<big><strong></strong></big><BR>\r\n</FONT>\r\n<blockquote>\r\n<TABLE border=0 cellPadding=1 width="80%">\r\n<TR><TD>\r\n<FONT face="Helvetica">\r\n<big>Network Error (tcp_error)</big>\r\n<BR>\r\n<BR>\r\n</FONT>\r\n</TD></TR>\r\n<TR><TD>\r\n<FONT face="Helvetica">\r\nA communication error occurred: "Operation timed out"\r\n</FONT>\r\n</TD></TR>\r\n<TR><TD>\r\n<FONT face="Helvetica">\r\nThe Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time.\r\n</FONT>\r\n</TD></TR>\r\n<TR><TD>\r\n<FONT face="Helvetica" SIZE=2>\r\n<BR>\r\nFor assistance, contact your network support team.\r\n</FONT>\r\n</TD></TR>\r\n</TABLE>\r\n</blockquote>\r\n</FONT>\r\n</BODY></HTML>'
这些是软件版本
- 火狐 ESR 17.0.5
- Selenium(Python 绑定)2.35.0
- Python 2.6.6
- Red Had Linux 6.3
- 已安装“Firefox WebDriver 2.35.0”浏览器扩展