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

运行Selenium时遇CDP版本不匹配问题,浏览器启动后秒崩

问题解决:Selenium ChromeDriver启动后浏览器崩溃

启动ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}),端口53398
仅允许本地连接。
请查看安全建议以保证ChromeDriver安全。
ChromeDriver启动成功。
2023年7月14日 下午2:25:21 org.openqa.selenium.remote.ProtocolHandshake createSession
信息:检测到上游方言:W3C
2023年7月14日 下午2:25:21 org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
警告:无法找到CDP版本114的精确匹配,因此返回找到的最接近版本:无操作实现
2023年7月14日 下午2:25:21 org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
信息:无法找到匹配114的CDP实现。
2023年7月14日 下午2:25:21 org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
警告:无法找到对应的CDP版本。你可能需要添加特定版本的CDP依赖,类似org.seleniumhq.selenium:selenium-devtools-v86:4.3.0,其中版本号("v86")要匹配你使用的基于Chromium的浏览器版本,artifact版本号要与Selenium版本一致。

问题根源

ChromeDriver(114版本)和Selenium依赖的CDP(Chrome开发者工具协议)版本不匹配,导致浏览器会话无法正常维持,最终几秒内崩溃。

具体修复步骤

  1. 添加对应版本的CDP依赖
    根据你的Selenium版本,引入匹配ChromeDriver 114的CDP依赖:

    • Maven项目,在pom.xml中加入:
      <dependency>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-devtools-v114</artifactId>
          <version>你的Selenium版本号</version> <!-- 比如4.10.0,必须和项目中selenium-java版本完全一致 -->
      </dependency>
      
    • Gradle项目,在build.gradle中加入:
      implementation 'org.seleniumhq.selenium:selenium-devtools-v114:你的Selenium版本号'
      

    重点:selenium-devtools-v114的版本号必须与项目中selenium-java的版本完全相同,否则仍会存在兼容性问题。

  2. 确认版本完全对齐
    检查以下三者版本必须保持一致:

    • 本地安装的Chrome浏览器版本
    • 下载的ChromeDriver版本
    • 引入的selenium-devtools版本(v114对应114.x系列)
  3. 升级Selenium到兼容版本
    如果你的Selenium版本过旧(比如低于4.10.0),可能原生不支持CDP 114,直接将Selenium升级到最新稳定版即可,同时同步升级selenium-devtools-v114的版本。

  4. 临时应急方案(不推荐长期使用)
    如果暂时无法调整依赖,可以尝试禁用CDP自动检测,初始化ChromeDriver时添加以下参数:

    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
    options.setExperimentalOption("useAutomationExtension", false);
    System.setProperty("webdriver.chrome.driver", "你的chromedriver路径");
    ChromeDriver driver = new ChromeDriver(options);
    

    注意:该方法会导致部分依赖CDP的功能失效,仅适合临时测试场景。

内容的提问来源于stack exchange,提问作者Midev K M

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 14:52:36