Selenium - How to configure GeckoDriver with proxy using Gecko Driver Service


  GeckoDriver - passing proxy and use of Gecko Driver Service

Firefox maintains its proxy configuration in a profile. One can set it on profile that is created on the fly as is shown in the following example. 
With GeckoDriver the proxy has to be passed through the required capabilities as described below 

String PROXY = "localhost";
int PORT = 8080;

com.google.gson.JsonObject json = new com.google.gson.JsonObject();
json.addProperty("proxyType", "MANUAL");
json.addProperty("httpProxy", PROXY);
json.addProperty("httpProxyPort", PORT);
json.addProperty("sslProxy", PROXY);
json.addProperty("sslProxyPort", PORT);

DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("proxy", json);

GeckoDriverService service =new GeckoDriverService.Builder(firefoxBinary)
  .usingDriverExecutable(new File("path to geckodriver"))
  .usingAnyFreePort()
  .usingAnyFreePort()
  .build();
service.start();

// GeckoDriver needs the Proxy set in RequiredCapabilities
driver = new FirefoxDriver(service, cap, cap);

No comments:

Post a Comment

How to handle categorical features with spark-ml?

How to Handle Categorical Features with Spark ML Categorical features are a type of feature that can take on a limited number of values, suc...