Alright, so my problem is that I can't find a way to launch Chrome with authenticated proxy connection. What I have is: proxy ip, port, username and password. What I need: to launch Chrome instance with connection with this proxy using Selenium
what I've tried:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=USERNAME:PASS@IP_ADDRESS:PORT"));
WebDriver driver = new ChromeDriver(capabilities);
and:
Proxy proxy = new Proxy();
proxy.setHttpProxy("IP_ADDRESS:PORT");
proxy.setSocksUsername("USERNAME");
proxy.setSocksPassword("PASSWORD");
ChromeOptions options = new ChromeOptions();
options.setProxy(proxy);
ChromeDriver driver = new ChromeDriver(options);
Unfortunately, none of this approaches work...
I was able to solve this problem by setting system-level proxy:
System.setProperty("java.net.useSystemProxies", "true");
// http
System.setProperty("http.proxyHost", "1.2.3.4");
System.setProperty("http.proxyPort", 8080);
System.setProperty("http.proxyUser", "username");
System.setProperty("http.proxyPassword", "pass");
// https
System.setProperty("https.proxyHost","1.2.3.4");
System.setProperty("https.proxyPort", 8080);
System.setProperty("https.proxyUser", "username");
System.setProperty("https.proxyPassword", "pass");
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
System.setProperty("jdk.https.auth.tunneling.disabledSchemes", "");
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("user", "pass".toCharArray());
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.