【发布时间】: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,不能使用这种方法。)
【问题讨论】: