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

IntelliJ中Selenium运行报错:CDP版本不匹配问题咨询

解决Selenium CDP版本不匹配警告问题

先明确你遇到的警告内容:

WARNING: Unable to find version of CDP to use for 127.0.6533.119. You may need to include a dependency on a specific version of the CDP using something similar to org.seleniumhq.selenium:selenium-devtools-v86:4.18.1 where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.

核心问题是Chrome浏览器版本(127.0.6533.119)和ChromeDriver版本(120.0.6099.109)不匹配,同时CDP依赖没对应上当前浏览器版本,完全不需要回退Chrome,按以下步骤解决:

  • 同步ChromeDriver与Chrome版本
    你的Chrome已经自动更新到127.x系列,但ChromeDriver还停留在120版本,这是根本矛盾。直接下载对应Chrome 127版本的ChromeDriver替换现有驱动即可——记住ChromeDriver主版本号必须和Chrome完全一致(比如Chrome是127.x.x.x,ChromeDriver就要用127.x.x.x)。

  • 配置正确的CDP依赖
    在POM.xml中添加对应Chrome 127版本的CDP依赖,且Selenium版本必须和CDP依赖版本完全相同。比如你的Selenium版本是4.19.x,依赖配置如下:

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-devtools-v127</artifactId>
        <version>4.19.1</version> <!-- 版本号要和你的Selenium版本保持一致 -->
    </dependency>
    

    之前添加依赖无效,大概率是选了错误的CDP版本(比如v86)或者Selenium版本和CDP版本不匹配。

  • 用WebDriverManager自动管理驱动(推荐)
    不想手动维护驱动版本的话,用WebDriverManager可以自动匹配Chrome和ChromeDriver版本,还能自动下载驱动。在POM.xml中添加依赖:

    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>5.6.3</version> <!-- 用最新稳定版即可 -->
    </dependency>
    

    代码里初始化驱动时调用:

    WebDriverManager.chromedriver().setup();
    WebDriver driver = new ChromeDriver();
    

按以上步骤操作后,CDP版本不匹配的警告就能解决,无需回退Chrome浏览器。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 14:06:06