c# - 如何接受带有 selenium firefox 驱动程序的自签名 SSL 证书?

标签 c# ssl selenium-webdriver selenium-firefoxdriver

我想在我的 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中。相反,我得到以下信息:

firefox ssl error page

最佳答案

直接在 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/

相关文章:

java - 使用selenium webdriver上传文件

c# - 如何在 C# 中为 protobuf map<string, string> 属性设置值

c# - 静默更新 PlannerTaskDetails 失败

python - Django AllAuth 给出 SSLError

delphi - IdHTTP + socks + socks 5

javascript - 点击Selenium on Sauce 发送后,Firefox 未完成页面加载

c# - 带有可移植数据库的简单 CRUD 应用程序

c# - 为什么结构中的迭代器可以修改这个?

java - 使用 Grizzly 和 Jersey 的 SSL

java - 在 Selenium 中选择不同行中的按钮