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

使用Selenium WebDriver启动应用URL时Java程序报错求助

问题解决:Selenium启动Chrome报错「无法找到Chrome二进制文件」

核心错误分析

你的报错信息里,Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: 无法启动新会话。响应码500。消息:unknown error: 无法找到Chrome二进制文件是导致程序失败的直接原因,SLF4J的警告只是日志框架的提示,不会阻止程序运行,优先解决核心问题。

解决方案

1. 确认Chrome浏览器安装路径

Windows系统下Chrome默认安装路径为:

  • C:\Program Files\Google\Chrome\Application\chrome.exe(64位系统)
  • C:\Program Files (x86)\Google\Chrome\Application\chrome.exe(32位或兼容模式)

手动检查该路径下是否存在chrome.exe,如果Chrome安装在自定义路径,记下完整路径。

2. 在代码中指定Chrome二进制文件位置

如果Chrome不在默认路径,通过ChromeOptions手动指定路径:

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class ChromeTest {
    public static void main(String[] args) {
        ChromeOptions options = new ChromeOptions();
        // 替换为你的Chrome实际安装路径
        options.setBinary("C:\\YourCustomPath\\Google\\Chrome\\Application\\chrome.exe");
        
        ChromeDriver driver = new ChromeDriver(options);
        driver.get("你的应用URL");
    }
}

3. 验证ChromeDriver与Chrome版本兼容性

确保你使用的ChromeDriver版本和本地Chrome浏览器版本大版本一致(比如Chrome 120对应ChromeDriver 120.x.x.x),版本不匹配也可能引发类似启动失败问题。


消除SLF4J警告(可选)

SLF4J警告是因为项目中只引入了SLF4J API,没有添加具体的日志实现。如果要消除警告,可以在项目依赖中添加以下任意一种:

Maven依赖

<!-- 使用slf4j-simple(简单日志实现) -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>2.0.9</version>
    <scope>test</scope>
</dependency>

或

<!-- 使用logback-classic(更强大的日志框架) -->
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.4.11</version>
</dependency>

Gradle依赖

// 使用slf4j-simple
testImplementation 'org.slf4j:slf4j-simple:2.0.9'

或

// 使用logback-classic
implementation 'ch.qos.logback:logback-classic:1.4.11'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 22:27:39