How to set Proxy setting for Chrome in Selenium Java

匿名 (未验证) 提交于 2019-12-03 01:10:02

问题:

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

回答1:

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


回答2:

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!