python - 无法使用 Selenium Webdriver 运行 Firefox

标签 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。

最佳答案

使用最新版本的 Selenium WebDriver

Python 的 Selenium 更新

  • 打开cmd提示
  • 找到文件夹 C:\Python27\Scripts在 cmd
    并输入

  • pip install -U selenium



    enter image description here

    关于python - 无法使用 Selenium Webdriver 运行 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16608342/

    相关文章:

    python - 如何在 apache 下从 mod_python 写入日志?

    python - 通过循环重命名列

    python - SQLAlchemy - 获取表的创建日期

    firefox - Firefox扩展程序,用于更改:config中的值

    html - div 不根据内部内容宽度扩展

    linux - self 更新 NuGet Ubuntu 16.04 后出错

    python - 将 datetime64 转换为不同的时间单位

    javascript - 强制(版本 10)Firefox 重新加载

    bash - 如何将 grep 的输出传递给 sed?

    linux - 无法使用适用于 Windows 10 的 Cygwin 在 ffmpegthumbnailer 安装文件上使用 Makefile