Use proxy with copying, via Selenium at java
-
Target: Start a browser with a proxy connection to which an authentication is required.
To install proxy in the browser manually, record the address and port in the browser compound. Thereafter, with first access to any server in the browser, a dialogue window for copying (basic authorization) is used. After it passes, all requests pass through proxy.
In the village, 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);
In this case, the connection configuration of the browser shall be placed on the address of the proxy.
<login>
, and the port is default ( zero). If you sign it,http://
the address is in place.http
and port zero.And I tried that:
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);
In this case, the address and port shall be correctly recorded after the browser has been launched (in the row)
WebDriver driver = new FirefoxDriver(capabilities);
(d) There is a dialogue window with the textПрокси «moz-proxy://<address>:<port>» запрашивает имя пользователя и пароль. Сайт сообщает: «proxy»
and locomotive and password fields, the programme is suspended, which prevents the use of the facilitydriver
to switch to the window and introduce logic and password (driver.switchTo().alert()....
)I also googled the option:
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);
But the result is the same as second.
Work should be at least in Firefox, and ideally in PhantomJS. In principle, there will be no unnecessary support for Chrome, but that's not necessary.
Update
Haven't no one ever seen this?
I've tried to use another option:
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");
If the proxy configuration is installed through the firefox probe ( profile.setPreference(...))), the proxy copying window appears a little earlier than the browser window (the browser starts around 1 second, and the copying window appears about half a second earlier) and, in contrast to the options for implementation from the previous communication, does not block the main window (which is launched/displayed a little later). Also in this option, the implementation of the programme is not suspended on the roadblock.
new FirefoxDriver(capabilities);
) The programme is suspended on the linedriver.get("http://2ip.ru");
, the browser expects a response from 2ip.ru, until I enter manual data to authorise the proxy, if the authorisation has failed, then instead of the page requested, I get a message - Proxy-Server refuses to accept the compounds.Question: How can you access the copying window to further login and spord entry, or how to copy on the proxy server without removing the copying window (as I have tried: proxy.setSocksUsername("); proxy.setSocksPassword("); )?
-
Decided through 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); } }