java - 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 驱动程序。
解决方案
终于让它工作了。首先,我尝试在另一个浏览器中访问打开的端口。
localhost:1250
在 URL 栏中输入内容。
它无法连接。因此,该端口显然存在问题。我尝试了许多不同的端口,但仍然遇到同样的问题。
我终于尝试了端口 1258,然后用上面列出的测试仔细检查了它。输入localhost:1258
另一个浏览器证明该端口是活动的。
然后我的程序也运行良好!多奇怪!很高兴它现在可以工作了:)
推荐阅读
- regex - 正则表达式:如何从此字符串中获取“按位”值之后的“宽度”和“高度”值?
- python-3.x - 计算python列表中具有相同元素值的对数
- kotlin - 使用 withContext 的协程执行顺序
- javascript - Jest 无法导入 TypeScript 文件
- javascript - 返回重复数字的数组
- ssl - Tomcat 9(Linux 服务器)上的 CA 认证 .cert 文件,tomcat 命令不起作用
- android - 如何从底部导航栏移动到活动 android
- c++ - GLFW 抛出“X11:Vulkan 实例缺少 VK_KHR_xcb_surface 扩展”,即使它位于 ppEnabledExtensionNames 中
- matlab - Matlab 函数可以创建全局变量吗?
- python-3.x - 子弹击中墙壁时游戏崩溃