This is the code I am using to start Firefox via Selenium Webdriver (Java):
private FirefoxDriver getfox(String pr) {
String geckoPath = "/opt/driver";
String browserPath = "/opt/browser";
String h = pr.split(":")[0];
String p = pr.split(":")[1];
System.setProperty("webdriver.firefox.marionette", geckoPath);
FirefoxProfile fp;
fp = new FirefoxProfile();
System.out.println("setting proxy " + h + ", port " + p);
fp.setPreference("network.proxy.http", h);
fp.setPreference("network.proxy.http_port", p);
FirefoxOptions fo = new FirefoxOptions();
fo.setProfile(fp);
fo.setBinary(browserPath);
FirefoxDriver driver = new FirefoxDriver(fo);
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30,TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(30,TimeUnit.SECONDS);
return driver;
}
However, when I enter about:config in the started browser and check the settings then only the proxy host has been changed. The http_port is set to 0. When I check my IP by navigating, e.g.,
Webdriver driver = getfox("host.proxy.server:port");
String address = "https://www.find-ip.net";
//String address = "http://www.find-ip.net";
System.out.println("navigating to " + address);
driver.get(address);
System.out.println("searching elements");
String selector = ("div.ipcontent.pure-u-13-24");
List<WebElement> elems = driver.findElements(By.cssSelector(selector));
for (WebElement w : elems) {
System.out.println(w.getText());
}
to http(s)://www.find-ip.net then I see my real IP address. The values I am passing are correct. I have no problem setting that proxy in HtmlUnit driver.
The versions involved are:
- Selenium 3.6.0
- Firefox 45.9.0
- geckodriver 19.0
Is there anything I need to change?