Firefox – How to set auto detect proxy settings in Selenium WebDriver using Java


Hi I am writing a Selenium WebDriver Java code/script.

public static WebDriver dr =null;
public static EventFiringWebDriver driver=null;

dr = new FirefoxDriver();

driver = new EventFiringWebDriver(dr);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

So Firefox browser is opening but proxy setting are stopping.

If it is manual I went to Tools->Options-Settings-> There I have given
Auto-detect proxy settings for this network
It is working.

But whenever I open by script I think new profile is opening. That's why I have set Auto-detect proxy settings for this network true by using script.

So can you please assist me how to do that?


Best Solution

This is the good solution:

import org.openqa.selenium.Proxy.ProxyType;` 

public static WebDriver dr = null;
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy(); 
proxy.setFtpProxy("proxy url"+":"+8080); 

DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(CapabilityType.PROXY, proxy); 
dr = new FirefoxDriver(dc);
Related Question