我正在尝试在ChromeDriver(适用于Chrome 75.0.3770.142)上打开带有身份验证的URL,该身份验证的密码包含字符“ @”,该解决方案是向URL添加用户名/密码,例如:“ https://username:p@ssword@www.test.com”甚至“ https://username:p%40ssword@www.test.com”对我也不起作用(实际上,它仅是第一次起作用,然后在所有下次运行中,浏览器都会显示身份验证弹出窗口并询问会话凭据)
然后,我尝试使用包含以下内容的zip文件(credential.zip)向chrome添加基本身份验证扩展名:
manifest.json
{
"manifest_version": 2,
"name": "Authentication for Cartier PreProd",
"version": "1.0.0",
"permissions": ["<all_urls>", "webRequest", "webRequestBlocking"],
"background": {
"scripts": ["background.js"]
}
}
background.js
var username = "username";
var password = "p@ssword";
var retry = 3;
chrome.webRequest.onAuthRequired.addListener(
function handler(details) {
if (--retry < 0)
return {cancel: true};
return {authCredentials: {username: username, password: password}};
},
{urls: ["<all_urls>"]},
['blocking']
);
在Selenium(3.141.59)中,我如下设置了一个远程驱动程序:
DesiredCapabilities capability = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.addArguments("--start-maximized");
File file = new File("src/main/resources/conf/credential.zip");
options.addExtensions(file);
capability.setCapability(ChromeOptions.CAPABILITY, options);
capability.setBrowserName("chrome");
capability.setPlatform(Platform.WINDOWS);
URL nodeUrl = new URL(<host:port>);
WebDriver driver = new RemoteWebDriver(nodeUrl, capability);
在午餐时,似乎无法加载扩展程序,引发错误:
unknown error: failed to wait for extension background page to load: chrome-extension://knocbjhpojhilndiecljamdcccjifakk/_generated_background_page.html
任何人都知道如何解决此问题?提前非常感谢!