You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium报‘binary is not a Firefox executable’错,求geckodriver及webdriver-manager解决方案

解决Selenium启动Firefox报"binary is not a Firefox executable"错误

针对你遇到的问题,以下是几个可行的解决方案:

1. 显式指定Firefox二进制文件路径

Selenium可能无法自动定位到正确的Firefox可执行文件(尤其是非默认安装路径的情况),可以通过FirefoxOptions手动指定:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager

options = FirefoxOptions()
# 根据你的系统修改路径:
# Windows示例
options.binary_location = r"C:\Program Files\Mozilla Firefox\firefox.exe"
# macOS示例
# options.binary_location = "/Applications/Firefox.app/Contents/MacOS/firefox"
# Linux示例
# options.binary_location = "/usr/bin/firefox"

driver = webdriver.Firefox(
    service=FirefoxService(GeckoDriverManager().install()),
    options=options
)
driver.get("http://selenium.dev")
print(driver.title)
driver.quit()

2. 验证版本兼容性

geckodriver 0.33.0要求Firefox版本为115及以上,请检查你的Firefox版本:

  • 打开Firefox → 点击右上角菜单 → 帮助 → 关于Firefox
  • 如果版本低于115,直接升级到最新兼容版本

3. 排查geckodriver路径冲突

执行以下命令确认系统路径中的geckodriver是否为你指定的0.33.0版本:

  • Windows:where geckodriver
  • macOS/Linux:which geckodriver

如果输出的路径不是你放置的版本,清理系统路径中的旧版本geckodriver,确保只有0.33.0版本在路径中。

4. 检查Firefox可执行文件权限(Linux/macOS)

如果是Linux或macOS系统,确保Firefox可执行文件有执行权限:

chmod +x /path/to/your/firefox

内容的提问来源于stack exchange,提问作者CodingForFun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 21:18:13