首页 > 解决方案 > Selenium WebDriver 设置调试器地址停止工作

问题描述

我正在使用 Selenium Web 驱动程序,但是,我通过设置 debuggerAddress 来预加载浏览器。我通过指定的端口连接。我有这个工作得很好。突然,它停止了工作。我不太确定问题是什么。

public void launchBrowser() throws InterruptedException {
        
        try {
         
            // Set file path of chrome driver
            System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
            
            // Start chrome driver with existing chrome browser 
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("debuggerAddress","localhost:1250");
            
            // Create object
            driver = new ChromeDriver(options);
            
            // Write to console where we are
            System.out.println(driver.getCurrentUrl());
            
        }
        catch(Exception e) {
         
            console("JacksClass.java","launchBrowser()", "Exception: " + e);
            
        }
        
    }

在我运行脚本之前。我在 CMD 中使用此命令启动 Chrome 浏览器

start chrome --remote-debugging-port=1250

从 CMD 成功启动浏览器后。然后运行代码。大约 1-2 分钟后出现以下异常。

JacksClass.java - launchBrowser() : Exception: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '4.0.0-alpha-6', revision: '5f43a29cfc'
System info: host: 'DESKTOP-5H32IOI', ip: '192.168.1.53', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.8'
Driver info: driver.version: ChromeDriver

一个月前,所有这些都运行良好。我在同一位置安装了 chrome 驱动程序。

在此处输入图像描述

标签: javaselenium-webdriver

解决方案


终于让它工作了。首先,我尝试在另一个浏览器中访问打开的端口。

localhost:1250在 URL 栏中输入内容。

它无法连接。因此,该端口显然存在问题。我尝试了许多不同的端口,但仍然遇到同样的问题。

我终于尝试了端口 1258,然后用上面列出的测试仔细检查了它。输入localhost:1258另一个浏览器证明该端口是活动的。

然后我的程序也运行良好!多奇怪!很高兴它现在可以工作了:)


推荐阅读