Chrome与ChromeDriver为109版本时Selenium CDP匹配警告问题求助
背景信息
你运行的基础Selenium Java代码如下:
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\BrowserDrivers\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.quit(); }
使用的配置:
- Selenium 4.x
- Chrome 版本109.0.5414.75(64位,Win10系统)
- ChromeDriver 109.0.5414.25
虽然程序能成功执行,但控制台出现两条CDP相关警告,以下是具体解析:
第一条警告解析
WARNING: Unable to find an exact match for CDP version 109, so returning the closest version found: a no-op implementation
这条警告的含义是:Selenium找不到与Chrome 109版本完全匹配的CDP(Chrome开发者工具协议)实现,只能返回一个空操作实现(no-op)。CDP是Selenium与Chrome浏览器交互的底层协议,负责支持网络拦截、性能监控、页面调试等高级功能。没有匹配的CDP版本,这些高级功能会失效,但打开/关闭浏览器这类基础WebDriver操作不受影响。
第二条警告解析
WARNING: Unable to find version of CDP to use for . 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.3.0where 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.
这条警告是明确的解决方案提示:你需要手动引入对应版本的CDP依赖包。当前你使用的Selenium 4.x版本默认没有内置Chrome 109对应的CDP模块,所以需要在项目依赖中添加类似这样的配置:
org.seleniumhq.selenium:selenium-devtools-v109:[你的Selenium版本号]
其中v109要和你的Chrome主版本号一致,依赖的版本号要和你使用的Selenium 4.x版本保持统一,添加后就能消除版本不匹配的警告。
为什么程序仍能正常运行?
因为你当前的代码只用到了WebDriver的最基础操作(启动、关闭浏览器),这类操作不依赖CDP的高级功能,所以即使没有匹配的CDP实现,程序依然可以正常执行。
内容的提问来源于stack exchange,提问作者undetected Selenium

