Answer the question
In order to leave comments, you need to log in
How to use proxy with authorization, through Selenium in java?
To set the proxy in the browser manually, I prescribe the address and port in the browser connection settings. After that, the first time you access any server in the browser, a dialog box pops up for authorization (basic authorization). After it passes, all requests go through the proxy.
--------------
In selenium I tried to do this:
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy("<login>:<password>@<address>:<port>");
proxy.setSslProxy("<login>:<password>@<address>:<port>");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://2ip.ru");
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy("<address>:<port>");
proxy.setSslProxy("<address>:<port>");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://2ip.ru");
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy("<address>:<port>");
proxy.setSslProxy("<address>:<port>");
proxy.setSocksUsername("<login>");
proxy.setSocksPassword("<password>");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://2ip.ru");
Пробовал использовать еще такой вариант:
DesiredCapabilities capabilities = new DesiredCapabilities(); // DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("signon.autologin.proxy" , true);
profile.setPreference("network.websocket.enabled", false);
profile.setPreference("network.proxy.share_proxy_settings", false);
profile.setPreference("network.automatic-ntlm-auth.allow-proxies", false);
profile.setPreference("network.http.phishy-userpass-length", 255);
profile.setPreference("network.auth.use-sspi", false);
profile.setPreference("network.proxy.http", "<address>");
profile.setPreference("network.proxy.http_port", <port>);
profile.setPreference("network.proxy.ssl", "<address>");
profile.setPreference("network.proxy.ssl_port", <port>);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setProxyType(ProxyType.MANUAL);
proxy.setSocksUsername("<login>");
proxy.setSocksPassword("<password>");
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://2ip.ru");
Answer the question
In order to leave comments, you need to log in
It was possible to install a local proxy without authorization, on which to register a proxy with authorization as a parent. In 3proxy
auth iponly
allow *
parent 1000 http ip_proxy port_proxy login password
proxy -i127.0.0.1 -p3128
Solved via AutoItX4Java:
private void mozProxyAuth(String login, String password) {
String JACOB_DLL_TO_USE = System.getProperty("sun.arch.data.model").contains("32") ? "jacob-1.18-x86.dll" : "jacob-1.18-x64.dll";
File file = new File(System.getProperty("user.dir"), JACOB_DLL_TO_USE);
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
if (x.winWait("Требуется аутентификация", null, 10)) {
x.winActivate("Требуется аутентификация");
x.send(login + "{TAB}" + password + "{ENTER}", false);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question