How to start selenium browser with proxy

Khoyendra Pande picture Khoyendra Pande · Mar 27, 2012 · Viewed 17.4k times · Source

I am trying to start selenium and selenium's browser with proxy but not getting success. I have used two methods:

        Properties sysProps = System.getProperties();
        sysProps.put("proxySet", "true");
        sysProps.put("proxyHost", "190.249.188.220");
        sysProps.put("proxyPort", "81");

and

java -jar lib/selenium-server.jar proxyHost=22.52.50.228 proxyPort=80

but both are not supporting.

is anyone able to help me to start selenium's browser with proxy.

Answer

Hai Nguyen picture Hai Nguyen · Sep 13, 2013

You can use this:

String PROXY = "localhost:8080";

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
     .setFtpProxy(PROXY)
     .setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);

WebDriver driver = new InternetExplorerDriver(cap);

For more detail, refer here