[英]How to perform proxy authentication in ChromeDriver using Selenium + Java?
好的,所以我的問題是我找不到使用經過身份驗證的代理連接啟動 Chrome 的方法。 我擁有的是:代理 ip、端口、用戶名和密碼。 我需要什么:使用 Selenium 啟動與此代理連接的 Chrome 實例
我試過的:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=USERNAME:PASS@IP_ADDRESS:PORT"));
WebDriver driver = new ChromeDriver(capabilities);
和:
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);
不幸的是,這些方法都不起作用......
我可以通過設置系統級代理來解決這個問題:
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());
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.