首页 > 解决方案 > 接受 C# selenium 中的证书 (.p12)

问题描述

我正在尝试找到一种方法来接受 C# selenium 中的证书弹出窗口。

我尝试了几种方法..没有任何帮助。

new Thread(() =>
{
    driver.Navigate().GoToUrl(url);
}).Start();
driver.SwitchTo().Alert().Accept(); // here I tried many type of ways to accept the popup, also key:enter ...

我也尝试了一些忽略的东西来添加, chromeOptions.AddArguments();但它也没有帮助。

有几个想法是不实际的 - 例如DesiredCapabilities不再可用。

没有帮助:

options.AddArgument("ignore-certificate-errors");
chromeOptions.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);

在此处输入图像描述

感谢您的任何想法或支持

标签: c#selenium-webdrivercertificateselenium-chromedriver

解决方案


以下代码有效(选项名称开头带有“--”):

var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--ignore-certificate-errors");

var chromeDriverLocation = Environment.GetEnvironmentVariable("ChromeWebDriver");
if (string.IsNullOrEmpty(chromeDriverLocation))
{
    chromeDriverLocation = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
}
WebDriver = new ChromeDriver(chromeDriverLocation, chromeOptions);

(完整代码在这里


推荐阅读