当访问特定站点并登录时,它要求我(通过我无法访问其 Web 元素的提示)使用特定证书来验证它以验证自己的身份。证书本身似乎已加载,但问题只是提交/单击“确定”响应。
所以,我尝试在网上查找,似乎确实有答案,但它们与我冲突。我在无头模式下运行 Chrome,这不允许我使用
autoit
或 pyautogui
库。我的钥匙串和 VSCode 中都有证书本身,但不确定如何将其提供给我的驱动程序以消除该提示。
这是我的代码的一部分:
def webdriverSetup():
chrome_options = Options()
#chrome_options.add_argument('--headless')
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--allow-running-insecure-content')
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(options=chrome_options)
return driver
注意:找到的其他一些答案是 Windows 独有的。暂时希望有 Mac 或“混合”解决方案,谢谢。
我建议尝试以下:
from selenium.webdriver.chrome.options import Options as ChromeOptions
chrome_options = ChromeOptions()
chrome_options.add_experimental_option(
'prefs', {
'required_client_certificate_for_user': <Path_to_certificate>
}
)
我从这里获得了首选项列表https://source.chromium.org/chromium/chromium/src/+/main:chrome/common/pref_names.cc以下是可以尝试的首选项列表:-
“user 所需的客户端证书”和“device 所需的客户端证书”
Selenium 本身不支持证书认证,但您可以使用 Selenium WebDriver 下载证书,然后使用 Selenium WebDriver 将证书导入到浏览器中。
我在 Java 中也遇到了同样的问题。您可以通过在 ChromeOptions 中添加以下参数直接在 Selenium 中取消此确认弹出窗口:“--ignore-urlfetcher-cert-requests”。
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--ignore-urlfetcher-cert-requests");
driver = new ChromeDriver(options);
在Python中,尝试添加:
chrome_options.add_argument('--ignore-urlfetcher-cert-requests')
无论如何,它在 Java 中对我有用!
我可以通过向 wdio 配置文件添加 chrome 选项来做到这一点:
capabilities: [
{
browserName: 'chrome',
'goog:chromeOptions': {
args: ["incognito","ignore-urlfetcher-cert-requests"]
}
}