草庐IT

java - Selenium : Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code

coder 2024-06-14 原文

我通过本地机器连接到 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

最佳答案

自上周以来,我也面临着这个问题。我搜索了很多并尝试了不同的方法来解决这个问题。下面的代码(伪代码)帮助我解决了这个问题。 我的方法:

  1. 运行 chromedriver.exe 服务器并检查端口号(我在我的代码中使用了 Process 类) 首先按照以下步骤手动检查:
    • 打开命令提示符
    • 导航到您的 chromedriver 所在的路径
    • 运行 chromedriver(只需输入 >chromedriver )
    • chromedriver 服务器将开始运行,记下端口号(在我的例子中是 9515)
  2. 使用 url ( http://localhost:portNumber ) 初始化驱动程序
  3. 通常的东西(最大化、超时、导航到 url)
  4. 编写测试脚本
  5. 关闭驱动实例(driver.close())
  6. 关闭流程实例(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/

有关java - Selenium : Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code的更多相关文章

随机推荐