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 it works fine. Now I need to pass those proxy setting while running the selenium code. Please help me on this.
I tried below code, but still it shows the same error:
Proxy p=new Proxy();
// Set HTTP Port to 7777
p.setHttpProxy("www.abc.com:8080");
// Create desired Capability object
DesiredCapabilities cap=new DesiredCapabilities();
// Pass proxy object p
cap.setCapability(CapabilityType.PROXY, p);
// Open firefox browser
WebDriver driver=new ChromeDriver(cap);
Open Google Chrome, click on the Settings icon, and Options. Select Under the hood, then Change proxy settings… Select Connections and LAN Settings. Select “Automatically detect settings”, and click OK.
Following piece of code used to set proxy in Selenium. ChromeOptions option = new ChromeOptions(); Proxy proxy = new Proxy(); proxy. setHttpProxy("localhost:5555"); option. setCapability(CapabilityType.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With