无法使用Selenium Webdriver运行Firefox

时间:2013-05-17 11:52:48

标签: python firefox ubuntu selenium

我正在尝试在Python中运行此代码:

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
profile = webdriver.FirefoxProfile()
browser = webdriver.Firefox(firefox_profile = profile)
# Create a new instance of the Firefox driver
driver = webdriver.Firefox()
# go to the google home page
driver.get("http://www.google.com")

当我运行它时,Firefox会在空白页面上启动一段时间,并保持这种状态。 我收到这条消息:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    browser = webdriver.Firefox(firefox_profile = profile)
  File "/home/fx/EnvDev/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 62, in __init__
    desired_capabilities=capabilities)
  File "/home/fx/EnvDev/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 72, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/home/fx/EnvDev/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 114, in start_session
    'desiredCapabilities': desired_capabilities,
  File "/home/fx/EnvDev/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 165, in execute
    self.error_handler.check_response(response)
  File "/home/fx/EnvDev/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 152, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: ''

我在代理后面的Ubuntu 12.04上使用Firefox 20.0。

1 个答案:

答案 0 :(得分:0)

使用最新版本的Selenium WebDriver

Python的Selenium更新

  1. 打开cmd提示
  2. 在cmd中找到文件夹C:\Python27\Scripts 并输入
  3.   

    pip install -U selenium

    enter image description here