12

I am able to set proxy settings for Firefox as below.

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setProxyType(ProxyType.MANUAL); 

proxy.setHttpProxy(CONFIG.getProperty("hostname"));
proxy.setSslProxy(CONFIG.getProperty("hostname"));
proxy.setFtpProxy(CONFIG.getProperty("hostname"));
proxy.setSocksUsername(CONFIG.getProperty("username"));
proxy.setSocksPassword(CONFIG.getProperty("password"));
FirefoxProfile fp = new FirefoxProfile();
fp.setProxyPreferences(proxy);

driver = new FirefoxDriver(fp);
builder = new Actions(driver); 
bckdbrowser = new WebDriverBackedSelenium(driver, ConfigReader.ENVIRONMENT_URL);

But I need to setup for Chrome as well.. Can any one assist me how to do ?

Thanks Raj

2 Answers 2

13

You can try using the DesiredCapabilities class, like this:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=http://user:[email protected]:8080"));
WebDriver driver = new ChromeDriver(capabilities);
Sign up to request clarification or add additional context in comments.

3 Comments

You mean should I give --proxy-server as it is ?
just use your own settings: capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=http://" + CONFIG.getProperty("username") + ":" + CONFIG.getProperty("password") + "@" + CONFIG.getProperty("hostname")));
it doesn't work for me. Which version of selenium and chrome was used?
-6

Try this code:

FirefoxProfile profile = new FirefoxProfile(); 

profile.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal()); 

WebDriver driver = new FirefoxDriver(profile);

here we have one more solution....it's worked for me

1 Comment

He`s asked about Chrome driver only.

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.