Raju
Raju

Reputation: 135

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?

Thanks Raju

Upvotes: 2

Views: 30278

Answers (4)

This is what I do to set auto detection:

FirefoxProfile profile = new FirefoxProfile();
Proxy proxy = new Proxy();
proxy.IsAutoDetect=true;
profile.SetProxyPreferences(proxy);
driver = new FirefoxDriver(profile);

Upvotes: 0

adwilson07
adwilson07

Reputation: 21

This is the solution that worked for me, a bit of a combo of the first two and simple enough. Did not need to do individual user authentication.

import org.openqa.selenium.Proxy.ProxyType;
import org.openqa.selenium.firefox.FirefoxProfile;

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", "proxy.something.com");
profile.setPreference("network.proxy.http_port", 8080);
profile.setPreference("network.proxy.ssl", "proxy.something.com");
profile.setPreference("network.proxy.ssl_port", 8080);


WebDriver driver = new FirefoxDriver(profile); 

Upvotes: 1

Raju
Raju

Reputation: 135

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);

Upvotes: 4

niharika_neo
niharika_neo

Reputation: 8531

You can set the preferences of the profile at runtime atleast with firefox driver. Give the following a try :

FirefoxProfile ff = new FirefoxProfile();
ff.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal());
FirefoxDriver ffD = new FirefoxDriver(ff);

Upvotes: 3

Related Questions