Selenium 安装 Marionette webdriver

Selenium install Marionette webdriver

我在使用 firefox 47 版时遇到了这个问题https://github.com/seleniumhq/selenium/issues/2110

所以,我尝试添加 Marionette 网络驱动程序来修复它:https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

但是:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/Users/myproject/geckodriver-0.8.0-OSX'

returns 错误:

selenium.common.exceptions.WebDriverException: Message: 'wires' executable needs to be in PATH.

Exception AttributeError: "'Service' object has no attribute 'process'" in > ignored

硒==2.53.5

您设置的 firefox 二进制功能指向 firefox 二进制文件,而不是 marionette 驱动程序二进制文件。您需要将 /Users/myproject/geckodriver-0.8.0-OSX 添加到您的路径中,如下所示:

打开终端并运行这个命令

export PATH=$PATH:/Users/myproject/geckodriver-0.8.0-OSX

ran into this issue and can confirm that firefox_capabilities['binary'] should point to the Firefox binary, not to GeckoDriver. The Python example in the Mozilla WebDriver documentation已经澄清了这个话题。

除了其他两个答案之外,您可能不想在整个系统范围内更改 PATH,因为只有在 运行 测试时才需要它。仅在需要时才拥有正确 PATH 的一种方法是在代码中设置它:

os.environ["PATH"] += os.pathsep + 'path/to/dir/containing/geckodriver/'

一个更简单的解决方法是将 geckodriver 二进制文件简单地移动到您路径中已有的目录:

mv geckodriver /usr/local/bin