【问题标题】:“Unable to find a matching set of capabilities” with Selenium and Python and current Firefox on Windows 10在 Windows 10 上使用 Selenium 和 Python 以及当前的 Firefox “无法找到一组匹配的功能”
【发布时间】:2018-04-03 04:20:20
【问题描述】:

我安装了以下内容:

  • 窗口 10(版本 1709)
  • Firefox v59(64 位)
  • Python 3.6.5
  • 用于 Python 的 Selenium 3.11.0
  • GeckoDriver 0.20.0

Selenium Python 官方网站有一个名为“Example 0”的示例测试:https://pypi.python.org/pypi/selenium。这是整个测试:

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')

当我运行它时,它会抱怨“selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

搜索 Stack Overflow 的解决方案,我找到了other suggested solutions,就像这个测试:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
browser = webdriver.Firefox(capabilities=cap, firefox_binary=binary)
browser.get('http://google.com/')

运行它,我收到以下错误: selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: C:\Users\Username\AppData\Local\Temp\tmp4t_plvms If you specified a log_file in the FirefoxBinary constructor, check it for details.

我有 Firefox v59,所以错误提示我应该使用 GeckoDriver。问题是,上面的第一个测试(“示例 0”)使用了 GeckoDriver,并且出现了“无法找到匹配的功能集”错误。该错误的建议解决方案是在第二个测试中设置“cap["marionette"] = False”,但该方法失败了。
我就是赢不了。我该如何解决这个问题?我想从 Selenium Python 官方网站成功运行“示例 0”测试。

(P.S. 这不是一个重复的问题。所有其他类似的问题都有 Firefox v54 或更早版本,并且能够使用“marionette = False”方法。我使用的是 Firefox 59,不能使用这种方法。)

【问题讨论】:

    标签: python selenium firefox


    【解决方案1】:

    原来,我有 Firefox 64 位、Python 3.6 32 位和 GeckoDriver 32 位。

    1. 我卸载了 Python 32 位,然后安装了 Python 64-bit
    2. 已下载 GeckoDriver 64 位并更正环境变量中的“路径”以指向 64 位驱动程序。
    3. 重新启动计算机。
    4. 我还运行了“pip uninstall selenium”,然后是“pip install selenium”,尽管这可能不是必需的。

    【讨论】:

      猜你喜欢
      • 2020-07-30
      • 2017-11-30
      • 2019-01-30
      • 2018-08-27
      • 2020-04-28
      • 2020-01-20
      • 2018-07-30
      • 2018-12-31
      相关资源
      最近更新 更多