How to set proxy for Chrome browser in selenium using Java code

后端 未结 5 1314
误落风尘
误落风尘 2021-02-08 15:08

I am trying to run my selenium java code to test a webpage. But webpage is not loading because of network restrictions. When I set the proxy manually and hit the url in browser

5条回答
  •  一整个雨季
    2021-02-08 15:44

    Passing a Capabilities object to the ChromeDriver() constructor is deprecated. You can find new official doc here.

    ChromeOptions chromeOptions = new ChromeOptions();
    
    Proxy proxy = new Proxy();
    proxy.setAutodetect(false);
    proxy.setHttpProxy("http_proxy-url:port"); 
    proxy.setSslProxy("https_proxy-url:port");
    proxy.setNoProxy("no_proxy-var");
    
    chromeOptions.setCapability("proxy", proxy); 
    driver = new ChromeDriver(chromeOptions);
    

提交回复
热议问题