我通过本地机器连接到 VPN 并尝试在 chrome 浏览器上执行 selenium 脚本然后我收到以下错误:
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1553947986.711][WARNING]: Timed out connecting to Chrome, retrying...
[1553947990.713][WARNING]: Timed out connecting to Chrome, retrying...
[1553947998.713][WARNING]: Timed out connecting to Chrome, retrying...
[1553948014.713][WARNING]: Timed out connecting to Chrome, giving up.
[1553948016.724][WARNING]: Timed out connecting to Chrome, retrying...
[1553948020.724][WARNING]: Timed out connecting to Chrome, retrying...
[1553948028.727][WARNING]: Timed out connecting to Chrome, retrying...
[1553948044.730][WARNING]: Timed out connecting to Chrome, giving up.
This is happening only when i want to execute the script through VPN, without VPN the script is working fine. For firefox browser not getting the above issue
最佳答案
自上周以来,我也面临着这个问题。我搜索了很多并尝试了不同的方法来解决这个问题。下面的代码(伪代码)帮助我解决了这个问题。 我的方法:
关闭流程实例(process.destroy())
尝试{
process = new ProcessBuilder("chromedriver.exe 的路径").start();
} catch (IOException e1){
e1.printStackTrace();
}
System.setProperty("webdriver.chrome.driver", "chromedriver.exe 路径");
ChromeOptions 选项 = new ChromeOptions();
尝试 {
driver = new RemoteWebDriver(新 URL(“http://127.0.0.1:9515”),选项);
} catch (MalformedURLException e){
e.printStackTrace();
}
//最大化浏览器
//删除所有 Cookie
//页面加载超时
//隐式等待
//导航到 url
//运行测试脚本
//关闭驱动
//关闭进程
希望它也能解决您的问题。如果您遇到任何问题,请告诉我。
关于java - Selenium : Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55431620/