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

ChromeDriver与Selenium Java中AddListener告警问题求助

问题诊断与修复指导

当前环境

  • ChromeDriver版本:110.0.5481.178(实际运行版本为110.0.5481.77)
  • 系统Chrome浏览器版本:110.0.5481.178
  • Java版本:17.0.5
  • Selenium Server版本:4.8.1(曾用4.7版本)

告警信息

Starting ChromeDriver 110.0.5481.77 (65ed616c6e8ee3fe0ad64fe83796c020644d42af-refs/branch-heads/5481@{#839}) on port 18129
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1677347917.891][WARNING]: virtual void DevToolsClientImpl::AddListener(DevToolsEventListener *) subscribing a listener to the already connected DevToolsClient. Connection notification will not arrive.

问题原因

  1. 版本不匹配:你声明使用的ChromeDriver版本(110.0.5481.178)与实际启动的版本(110.0.5481.77)不一致,导致ChromeDriver与Chrome浏览器的DevTools协议交互出现时序冲突。
  2. 监听器时序问题:Selenium在DevTools客户端已建立连接后才添加监听器,触发告警,这通常是版本不匹配引发的连锁问题。

分步修复指导

1. 定位并清理旧版本ChromeDriver

  • Windows系统:打开命令提示符,执行 where chromedriver,查看所有ChromeDriver的路径,删除版本为110.0.5481.77的文件。
  • Linux/macOS系统:在终端执行 which chromedriver 或 find / -name chromedriver,找到旧版本文件并删除。

2. 明确指定ChromeDriver路径

在Java代码中直接指定正确版本ChromeDriver的绝对路径,避免系统调用旧版本:

import org.openqa.selenium.chrome.ChromeDriver;

public class ChromeTest {
    public static void main(String[] args) {
        // 替换为你的ChromeDriver实际路径
        System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver-110.0.5481.178");
        ChromeDriver driver = new ChromeDriver();
        // 后续操作...
        driver.quit();
    }
}

3. 检查Selenium依赖冲突

确保项目依赖中只有Selenium 4.8.1的相关jar包,排除任何旧版本的Selenium依赖(比如4.7版本的残留)。如果使用Maven,可在pom.xml中添加依赖排除:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.8.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>4.8.1</version>
</dependency>

4. 临时规避方案(若上述步骤无效)

通过ChromeOptions禁用自动DevTools连接,避免监听器时序问题:

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.Collections;

public class ChromeTest {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver-110.0.5481.178");
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
        ChromeDriver driver = new ChromeDriver(options);
        // 后续操作...
        driver.quit();
    }
}

5. 验证修复效果

重新运行代码,查看日志确认启动的ChromeDriver版本为110.0.5481.178,且不再出现DevTools相关告警。

内容的提问来源于stack exchange,提问作者Abubakar Arshad

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 04:15:26