我想在我的 ASP.NET Core 2.1 Web 应用程序上运行一些自动浏览器测试。对于这个应用程序,我启用了 HttpsRedirection,并运行了命令 dotnet dev-certs https --trust
信任 ASP.NET Core 使用的 ssl 证书。
我已经下载了 firefox selenium 驱动程序并将可执行文件添加到我的 PATH 中。当我运行代码时,这会打开一个 Firefox 窗口。
接受风险并继续没有任何作用,因为代码已经与浏览器断开连接。
var firefoxOptions = new FirefoxOptions();
var profile = new FirefoxProfile();
profile.AcceptUntrustedCertificates = true;
// Tried the following, got this: Invalid moz:firefoxOptions field acceptInsecureCerts
// firefoxOptions.AddAdditionalCapability(CapabilityType.AcceptInsecureCertificates, true);
firefoxOptions.Profile = profile;
var driver = new FirefoxDriver(firefoxOptions);
driver.Url = "http://localhost:5002/";
我希望被带到我的网络应用程序,就像我浏览到
http://localhost:5002
时一样我自己在Firefox中。相反,我得到以下信息:最佳答案
直接在 FireFoxOptions 而不是配置文件上设置参数...
var firefoxOptions = new FirefoxOptions();
firefoxOptions.AcceptInsecureCertificates = true;
我还注意到您的 URL 不是 https,如果您想接受不安全的证书,您可能应该浏览到 https,即driver.Url = "https://localhost:5002/";
关于c# - 如何接受带有 selenium firefox 驱动程序的自签名 SSL 证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57198343/