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

求助:ChromeDriver与Chrome版本不兼容导致无法创建会话(Java/Windows)

环境信息

  • 操作系统:Windows Server
  • 开发语言:Java
  • Chrome浏览器版本:120.0.6099.130
  • ChromeDriver版本:114.0.5735.90

报错信息

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 120.0.6099.130 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe 
Host info: host: 'CATPOWER', ip: '***'
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '19.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*], extensions: []}}]}]
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:140)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:96)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:68)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:196)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:171)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:232)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:159)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:108)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:83)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:51)
    at mangia.ro.Autentificare.setup(Autentificare.java:18)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
    at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:361)
    at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:296)
    at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:644)
    at org.testng.TestRunner.beforeRun(TestRunner.java:633)
    at org.testng.TestRunner.run(TestRunner.java:595)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:437)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:431)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:391)
    at org.testng.SuiteRunner.run(SuiteRunner.java:330)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
    at org.testng.TestNG.runSuites(TestNG.java:1099)
    at org.testng.TestNG.run(TestNG.java:1067)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

我尝试更新ChromeDriver版本但未成功,不清楚后续操作步骤,恳请提供技术帮助。


解决步骤

1. 严格匹配版本

ChromeDriver必须与Chrome浏览器主版本号一致(你的Chrome是120.x,需下载120.x版本的ChromeDriver)。

2. 替换旧驱动

  • 下载对应Windows平台的120.x版本ChromeDriver,解压得到chromedriver.exe。
  • 找到项目中当前使用的chromedriver.exe路径,直接替换为新文件;或者在代码中指定新路径:
System.setProperty("webdriver.chrome.driver", "C:\\你的新驱动路径\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();

3. 验证版本正确性

打开命令行,进入ChromeDriver所在目录,执行:

chromedriver --version

确认输出版本主号为120。

4. 自动管理驱动(推荐)

避免手动更新的麻烦,使用WebDriverManager库自动匹配版本:

  • Maven添加依赖:
<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.6.0</version>
</dependency>
  • 代码中使用:
WebDriverManager.chromedriver().setup();
ChromeDriver driver = new ChromeDriver();

该库会自动检测Chrome版本,下载对应ChromeDriver,无需手动操作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 09:36:02