我正在使用带有Selinium的BrowserMob来处理我的基本身份验证弹出窗口,它在Firefox上可以正常使用,但在Chrome上却不能。我的代码如下。我的Firefox代码和Chrome代码之间的唯一区别是chromeOptions.addArguments()行。我的控制台输出是
启动ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs / branch-heads / 3770 @ {#1003}) 在端口47145上
仅允许本地连接。
请保护ChromeDriver和相关测试框架使用的端口 防止恶意代码访问。
2019年6月17日上午10:00:15 org.openqa.selenium.remote.ProtocolHandshake createSession
INFO:检测到的方言:W3C
我的Chrome浏览器由我的组织管理。我尝试用chromeOptions.setCapability(CapabilityType.PROXY,seleniumProxy);
替换chromeOptions.setProxy(seleniumProxy);
行,但仍然行不通。
我正在使用BrowserMob 2.1.5
,ChromeDriver 75.0.3370.90
,Google Chrome版本75.0.3770.90(正式版本)(32位)和Selenium 3.141.59
browserMobProxy = getProxyServer(username, password);
Proxy seleniumProxy = getSeleniumProxy(browserMobProxy);
System.setProperty("webdriver.chrome.driver","P:/AppDev/MIS Projects/Selenium/chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("user-data-dir=" + profileLocation);
chromeOptions.addArguments("disable-infobars");
chromeOptions.setCapability(CapabilityType.PROXY, seleniumProxy);
private static BrowserMobProxy getProxyServer(String username, String password) {
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.setTrustAllServers(true);
proxy.start();
String credentials = username + ":" + password;
String encodedCreadentials = "Basic " + (Base64.getEncoder().encodeToString(credentials.getBytes()));
proxy.addHeader("Authorization", encodedCreadentials);
return proxy;
}
public static Proxy getSeleniumProxy(BrowserMobProxy proxyServer) {
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxyServer);
try {
String hostIp = Inet4Address.getLocalHost().getHostAddress();
seleniumProxy.setHttpProxy(hostIp + ":" + proxyServer.getPort());
seleniumProxy.setSslProxy(hostIp + ":" + proxyServer.getPort());
} catch (UnknownHostException e) {
e.printStackTrace();
Assert.fail("invalid Host Address");
}
return seleniumProxy;
}