【问题标题】:Can't run Firefox with Selenium Webdriver无法使用 Selenium Webdriver 运行 Firefox
【发布时间】:2013-05-17 11:52:47
【问题描述】:

我正在尝试在 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。

【问题讨论】:

  • 该代码对我有效,没有任何错误。尝试重新安装 selenium 并再试一次。
  • 我已经这样做了(我使用 pip install Selenium 安装)。
  • 这个问题会不会是代理造成的?
  • 你试过不使用代理吗?

标签: python firefox ubuntu selenium


【解决方案1】:

使用最新版本的 Selenium WebDriver

Python 的 Selenium 更新

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

pip install -U selenium

【讨论】:

    猜你喜欢
    • 2019-03-15
    • 2015-02-28
    • 2017-06-03
    • 2017-05-08
    • 2017-03-09
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多