selenium 3.0使用木偶不在firefox49上工作

时间:2016-12-14 07:13:58

标签: python-2.7 selenium

我正在使用带有python 2.7绑定的selenium 3.0版本。当我试图在firefox 49上启动代码时,它抛出一个异常,以下是我的代码

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
firefox_capabilities = DesiredCapabilities.FIREFOX


firefox_capabilities['marionette'] = True


binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)

geckodriver="/Users/pmarques/Test/geckodriver"

driver = webdriver.Firefox(capabilities=caps, executable_path="C:\\python code\\geckodriver\\geckodriver.exe")

driver.get("http://www.google.com")

发现错误

C:\python code>python testfirefox.py
Traceback (most recent call last):
  File "testfirefox.py", line 11, in <module>
    driver = webdriver.Firefox(firefox_binary=binary)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 140, in __init__
    self.service.start()
  File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", lin
e 96, in start
    self.assert_process_still_running()
  File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", lin
e 109, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unex
pectedly exited. Status code was: 2

1 个答案:

答案 0 :(得分:0)

您需要在一个命令中初始化驱动程序

binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, capabilities=caps, executable_path="C:\\python code\\geckodriver\\geckodriver.exe")