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

autoproxyfirefoxproxyselenium-webdriver

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?

Thanks
Raju

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.setSslProxy("proxyurl"+":"+8080); 
proxy.setFtpProxy("proxy url"+":"+8080); 
proxy.setSocksUsername("SSSLL277"); 
proxy.setSocksPassword("password"); 

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