大约有 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 :消息:无法找到匹配的功能集
我正在运行的软件版本:
火狐浏览器:62.0(64 位)
硒:3.14.0
壁虎:0.21.0
蟒蛇:3
操作系统:Windows 8.1 64 位
任何帮助将不胜感激。
编辑:我已经卸载并重新安装了 Firefox,但没有用。还尝试安装 Firefox 61.0.2,仍然没有成功。
原文由 Anish 发布,翻译遵循 CC BY-SA 4.0 许可协议
这个错误信息…
…暗示 GeckoDriver 无法启动/生成新的 WebBrowser ,即 Firefox 浏览器 会话。
您需要处理以下几件事:
FirefoxBinary
您需要使用FirefoxOptions()
而不是传递 geckodriver 二进制文件的 _绝对路径_,您必须传递所需的 firefox 二进制文件的 _绝对路径_。true
),要么将 木偶 设置为true
。