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

使用Selenium无法启动Firefox浏览器问题求助

解决Selenium启动Firefox失败的问题

错误核心原因

报错提示Expected browser binary location, but unable to find binary in default location,说明GeckoDriver无法定位到Firefox浏览器的二进制执行文件——要么Firefox没安装在系统默认路径,要么代码中未显式指定浏览器位置。

解决方案

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

修改代码,通过FirefoxOptions配置Firefox.exe的实际安装路径,示例代码如下:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;

public class BrowserTest {
    public static void main(String[] args) {
        System.setProperty("webdriver.gecko.driver", "D:\\Selenium\\BrowserJars\\geckodriver113.exe");
        
        // 配置Firefox二进制文件路径
        FirefoxOptions options = new FirefoxOptions();
        // 替换为你实际的Firefox安装路径,Windows默认路径参考如下
        options.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
        
        WebDriver driver = new FirefoxDriver(options);
    }
}

Windows系统中Firefox默认安装路径通常为C:\Program Files\Mozilla Firefox\firefox.exe(64位)或C:\Program Files (x86)\Mozilla Firefox\firefox.exe(32位),请根据实际安装位置调整。

2. 确认GeckoDriver路径有效性

检查webdriver.gecko.driver配置的文件路径、文件名是否完全正确,确保文件存在且无拼写错误。

3. 版本兼容性验证

你的Firefox 113与GeckoDriver 0.33.0版本是兼容的(GeckoDriver 0.33.0适配Firefox 109-115版本区间),这部分无需调整。

额外检查点

  • 若使用便携版Firefox,必须显式指定二进制文件路径
  • 确认Eclipse项目中Selenium依赖包版本(4.9.1)与GeckoDriver版本适配

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 09:13:20