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

Windows下使用Python Selenium遇'binary is not a Firefox executable'错误求助

问题解决

你的代码中options.binary_location的赋值方式存在错误,多写了executable_path=关键字,正确的写法是直接将Firefox可执行文件的路径字符串赋值给binary_location。

修正后的代码如下:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options

driver_service = Service(executable_path=r"C:\Program Files (x86)\geckodriver.exe")

options = Options()
# 移除多余的executable_path=,直接赋值路径字符串
options.binary_location = r"C:\Program Files\Mozilla Firefox\firefox.exe"
driver = webdriver.Firefox(service=driver_service, options=options)
driver.get("https://google.com")

额外检查项:

  • 再次确认路径指向的是真实的firefox.exe文件,而非快捷方式
  • 确保运行代码的用户对该文件路径拥有读取权限

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 12:07:03