我在使用 Selenium WebDriver 时遇到 WebSocket 问题,描述了相同的问题here https://groups.google.com/g/chromedriver-users/c/xL5-13_qGaA。问题的解决方案是添加--remote-allow-origins=*
我的驱动程序的 ChromeOptions 参数。但是,我不想为此参数使用通配符。我想将其设置为仅允许来自我的应用程序的连接。
我相信解决方案将涉及预先确定 WebDriver 的端口。这是我最好的尝试,但它不起作用:
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito", "--app=" + linkedform);
int port;
try (ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
} catch (IOException e) {
throw new RuntimeException(e);
}
options.addArguments("--remote-allow-origins=http://localhost:" + port);
ChromeDriverService service = new ChromeDriverService.Builder().usingPort(port).build();
this.chrome = new ChromeDriver(service, options);
我走在正确的道路上吗?这可能吗?
WebSocket 问题现已从 selenium 4.8.2/4.8.3 开始修复,调用期间无需在 chrome 选项中添加“--remote-allow-origins=*”。相反,我们现在可以直接更新 pom.xml 中的 selenium 依赖项。
更新日志:
v4.8.3
- 支持的 CDP 版本:85、109、110、111
- 修复阻止将项目添加到 Selenium Manager 命令的 ArrayList 的错误
v4.8.2
- 支持的 CDP 版本:85、109、110、111
- [网格] 启用
detectDrivers
原始行为。
- 修复 4.8.0 中的 NPE 回归 (#11701)
- 实现完全独立于服务类的 DriverFinder (#11491)
- [grid] 允许 LocalNode 扩展以进行自定义 (#11718)
- InvalidSelectorException 扩展了 WebDriverException (#11727)
- 弃用 FirefoxDriver 中的 CDP 实例方法
- 将allowHosts添加到GeckoDriverService
- [grid] 将语言环境变量传递给子容器
- [grid] 删除 IE 的未知功能扩展
- [bidi] 确保删除侦听器不会导致错误
- 将 Selenium Manager 输出处理为 JSON (#11663)
- [grid] 支持 Grid 中的远程下载 (#11702)
- Adding
remote-allow-origins
适用于 Chrome
- 仅使用“--browser”调用 Selenium Manager
- [网格] 添加
remote-allow-origins
对于 Chrome 刻板印象
- 重载构造函数来配置 WebDriver 对象的连接和读取超时 (#11532)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)