3

我正在尝试使用包含字符“@”的密码的身份验证在 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 添加基本身份验证扩展:

清单.json

{
  "manifest_version": 2,
  "name": "Authentication for Cartier PreProd",
  "version": "1.0.0",
  "permissions": ["<all_urls>", "webRequest", "webRequestBlocking"],
  "background": {
    "scripts": ["background.js"]
  }
}

背景.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);

午餐 WebDriver 时,它似乎无法加载扩展,它抛出一个错误:

unknown error: failed to wait for extension background page to load: chrome-extension://knocbjhpojhilndiecljamdcccjifakk/_generated_background_page.html

任何人都知道如何解决这个问题?提前非常感谢!

4

0 回答 0