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

后端 未结 5 1377
误落风尘
误落风尘 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:26

    DesiredCapabilities dc;
    dc = DesiredCapabilities.chrome();              
    System.setProperty("http.proxyHost", "127.0.0.1");
    System.setProperty("http.proxyPort", "9090");
    System.setProperty("https.proxyHost", "127.0.0.1");
    System.setProperty("https.proxyPort", "9090");                      
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    options.addArguments("--disable-extensions");
    dc.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new ChromeDriver(dc);
    

提交回复
热议问题