dimanche 14 mars 2021

Browsermob proxy is blocking connection

I'm trying to sign in to this website with Selenium (Chrome) via BrowserMob proxy. Without this proxy I can sign in successfully, but when I add it to WebDriver capabilities capabilities.setCapability(CapabilityType.PROXY, seleniumProxy); - the website is starting to refuse connection. The next error on the website is shown: Sorry, unable to connect to our server. What it could be ? How to fix this issue ? Initialization code:

this.proxyServer = new BrowserMobProxyServer();
this.proxyServer.start();

HashMap<String, Object> chromePrefs = new HashMap<>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadPath);

ChromeOptions options = new ChromeOptions();

Proxy seleniumProxy = ClientUtil.createSeleniumProxy(this.proxyServer);
DesiredCapabilities capabilities = new DesiredCapabilities();

String host = seleniumProxy.getHttpProxy().split(":")[0];
int port = Integer.parseInt(seleniumProxy.getHttpProxy().split(":")[1]);
chromePrefs.put("network.proxy.type", 1);
chromePrefs.put("network.proxy.http", host);
chromePrefs.put("network.proxy.http_port", port);
chromePrefs.put("network.proxy.ssl", host);
chromePrefs.put("network.proxy.ssl_port", port);
chromePrefs.put("acceptInsecureCerts", true);

options.setExperimentalOption("prefs", chromePrefs);
options.setAcceptInsecureCerts(true);

capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
options.merge(capabilities);

this.webDriver = new ChromeDriver(options);
this.webDriverWait = new WebDriverWait(webDriver, 10);



Aucun commentaire:

Enregistrer un commentaire