Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start selenium browser with proxy

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.

like image 476
Khoyendra Pande Avatar asked Mar 27 '12 07:03

Khoyendra Pande


People also ask

Can we handle a proxy using Selenium in Java?

Alerts are simple, inbuilt feature provided by Selenium web driver. You can handle proxy authentication popups using Selenium web driver by switching to the HTTP proxy authentication alert and passing the user name and password directly to the alert.


2 Answers

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

like image 118
Hai Nguyen Avatar answered Oct 13 '22 18:10

Hai Nguyen


try

java -Dhttp.proxyHost=HOSTNAME -Dhttp.proxyPort=PORT -Dhttp.proxyUser=USER -Dhttp.proxyPassword=PASSWORD -jar selenium-server.jar

* Dhttp.proxyHost – proxy IP address
* Dhttp.proxyPort – proxy port
* Dhttp.proxyUser – user name if HTTP-proxy authentication required;
* Dhttp.proxyPassword – user password if HTTP-proxy authentication required.
like image 35
Alex Stybaev Avatar answered Oct 13 '22 19:10

Alex Stybaev