2

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

1
  • have you tried creating new firefox profile and use for selenium tests. follow this how to click this once created use about:config and set value for network.proxy.type as 2 Commented Jan 9, 2013 at 13:26

4 Answers 4

4

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);
Sign up to request clarification or add additional context in comments.

1 Comment

and for http proxy : proxy.setHttpProxy("http://${login}:${password}@${proxy}:${port}");`
3

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

9 Comments

Do you get some error? What version of webdriver are you on? I have checked the code and when i put a breakpoint, I see the setting done in the browser launched by driver.
In code no error... After opening a firfox Server not found Firefox can't find the server at www.quikr.com. Check the address for typing errors such as ww.example.com instead of www.example.com If you are unable to load any pages, check your computer's network connection. If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
I have modified code like this public static WebDriver dr =null; FirefoxProfile ff = new FirefoxProfile(); ff.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal()); FirefoxDriver ffD = new FirefoxDriver(ff); dr = new FirefoxDriver(ffD);
I am using latest Webdriver 2.28.0
1. Why do u need to have 2 drivers? 2. I tried the above code with the last statement as ffD.get("google.com"). Works for me..Have you tried with some other url?
|
1

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

2 Comments

This worked for me too (network.proxy.type is crucial), but if the application runs on localhost (my case), one may want to add: profile.setPreference("network.proxy.no_proxies_on", ""); Default value is localhost, 127.0.0.1
For localhost you may need another profile setting, that does not relate to proxy - but it kept replacing localhost/something for www.localhost.com/something. Just add: profile.setPreference("browser.fixup.alternate.enabled", false);
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.