【发布时间】:2019-02-18 13:37:56
【问题描述】:
大约有 100 篇关于同一问题的帖子,但似乎没有一个对我有用,因此再次询问。我正在尝试使用 Python 和 Selenium 启动 Firefox 浏览器,但出现以下错误:
WebDriverException:消息:在我们连接之前浏览器似乎已经退出。如果您在 FirefoxBinary 构造函数中指定了 log_file,请检查它以获取详细信息。
我尝试了网络上的每一个答案,但似乎没有任何效果。
这是我的代码:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
caps["marionette"] = False
binary = FirefoxBinary('d:\\Desktop\\IEDriver\\geckodriver.exe')
options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(firefox_binary=binary, firefox_options=options, executable_path=r'd:\\Desktop\\IEDriver\\geckodriver.exe')
driver.get("http://google.com/")
print ("Headless Firefox Initialized")
driver.quit()
如果我设置caps["marionette"] = True 那么我得到的错误是
SessionNotCreatedException:消息:无法找到匹配的功能集
我正在运行的软件版本:
Firefox:62.0(64 位)
硒:3.14.0
壁虎:0.21.0
Python:3
操作系统:Windows 8.1 64 位
任何帮助将不胜感激。
编辑:我已经卸载并重新安装了 Firefox,但没有工作。也试过安装 Firefox 61.0.2,还是不行。
【问题讨论】:
-
firefox_binary应该是您的 Firefox 可执行文件 (firefox.exe) 的路径,但不是geckodriver.exe
标签: python-3.x selenium firefox selenium-webdriver geckodriver