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

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

    Another way of doing it:

            boolean useProxy = true;
            ChromeOptions options = new ChromeOptions().addArguments(
                    '--headless',
                    '--no-sandbox',
                    '--disable-extensions',
                    '--proxy-bypass-list=localhost');
            if (useProxy) {
                options.addArguments("--proxy-server=http://ProxyHost:8080");
            }
    
            WebDriver driver = new ChromeDriver(options);
    

    See https://peter.sh/experiments/chromium-command-line-switches/ for more Chrome switches

提交回复
热议问题