【问题标题】:How to turn off the proxy settings on chrome browser through selenium webdriver?如何通过 selenium webdriver 关闭 chrome 浏览器上的代理设置?
【发布时间】:2015-10-08 07:28:08
【问题描述】:

当我在 chrome 上导航到我的 url 时,我得到 The system cannot find the file specified." 。我认为这可能是由于 chrome 上的自动代理设置。 我想在 selenium 中启动 chrome 浏览器之前明确关闭代理设置。我在下面尝试过,它不起作用。谁能帮帮我

ChromeOptions options = new ChromeOptions();
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability("chrome.setProxyByServer", false);
System.setProperty("webdriver.chrome.driver",sChromeDriverPath);
WebDriver driver = new ChromeDriver();

在任何时候都不会引发错误,但 URL 不会打开

蒂亚 安佳娜

【问题讨论】:

    标签: java selenium proxy selenium-chromedriver


    【解决方案1】:

    您需要在初始化时将选项对象传递给 chrome 驱动程序。如果您使用特定功能,则将其传递给chromeDriver(),以便 chrome 知道从什么开始。 chrome 中也没有 JSON 对象作为 setProxyByServer,而是使用 noProxy JSON 对象。 Check this out. 方法如下 -

    Proxy proxy=startProxy();
    proxy.setProxyType(ProxyType.MANUAL); 
    proxy.setNoProxy("");
    ChromeOptions options = new ChromeOptions();
    DesiredCapabilities dc = DesiredCapabilities.chrome();
    dc.setCapability(CapabilityType.PROXY, proxy);
    System.setProperty("webdriver.chrome.driver",sChromeDriverPath);
    dc.setCapability(ChromeOptions.CAPABILITY, options);
    WebDriver driver = new ChromeDriver(dc);
    

    More info about chrome capabilities。希望对您有所帮助。

    【讨论】:

    • 有多傻?其实没注意到。感谢您指出。但不幸的是问题仍然没有解决。
    • @Anjana 那是因为 chrome 对象上没有 setProxyByServer,它仅用于 IE 浏览器。而是使用可用的noProxy JSON 对象。用它更新了代码。
    猜你喜欢
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 2019-05-14
    • 2019-01-19
    • 2020-06-26
    • 1970-01-01
    相关资源
    最近更新 更多