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

如何在Selenium Java中为Chrome设置代理设置,java,selenium-webdriver,Java,Selenium Webdriver,我可以如下设置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(CO

我可以如下设置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);

这里我们还有一个解决方案……它对我很有用。

你的意思是我应该给--proxy server原样吗?只需使用你自己的设置:
capabilities.setCapability(“chrome.switches”,Arrays.asList”(--proxy server=http://“+CONFIG.getProperty(“username”)+:“+CONFIG.getProperty(“password”)+“@”+CONFIG.getProperty(“主机名”)它对我不起作用。使用了哪个版本的selenium和chrome?他只问了chrome驱动程序。