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

Andrea
  • 11,801
  • 17
  • 65
  • 72
user1140680
  • 123
  • 1
  • 1
  • 4

2 Answers2

13

You can try using the DesiredCapabilities class, like this:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=http://user:password@proxy.com:8080"));
WebDriver driver = new ChromeDriver(capabilities);
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Farlan
  • 1,860
  • 2
  • 28
  • 37
  • You mean should I give --proxy-server as it is ? – user1140680 Oct 07 '13 at 13:45
  • just use your own settings: `capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=http://" + CONFIG.getProperty("username") + ":" + CONFIG.getProperty("password") + "@" + CONFIG.getProperty("hostname")));` – Farlan Oct 08 '13 at 13:43
  • 7
    it doesn't work for me. Which version of selenium and chrome was used? – Maksym Aug 06 '16 at 21:54
-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

iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
satender
  • 1,199
  • 13
  • 12