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

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

    Issue is resolved with below code -

    Proxy proxy = new Proxy(); 
    proxy.setHttpProxy("yoururl:portno"); 
    proxy.setSslProxy("yoururl:portno"); 
    
    DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
    capabilities.setCapability("proxy", proxy); 
    
    ChromeOptions options = new ChromeOptions(); 
    options.addArguments("start-maximized"); 
    
    capabilities.setCapability(ChromeOptions.CAPABILITY, options); 
    
    driver = new ChromeDriver(capabilities);
    

提交回复
热议问题