如何在Selenium Java中设置Chrome的代理设置

我可以为Firefox设置代理设置,如下所示。

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

但我也需要为Chrome设置..任何人都可以帮我怎么办?

谢谢Raj

您可以尝试使用DesiredCapabilities类,如下所示:

 DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=http://user:password@proxy.com:8080")); WebDriver driver = new ChromeDriver(capabilities); 

试试这段代码:

 FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal()); WebDriver driver = new FirefoxDriver(profile); 

在这里,我们还有一个解决方案….它对我有用