【问题标题】:How to accept self-signed SSL certificates with selenium firefox driver?如何接受带有 selenium firefox 驱动程序的自签名 SSL 证书?
【发布时间】:2019-12-03 12:25:57
【问题描述】:

我想在我的 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/";

我希望被带到我的网络应用程序,就像我自己在 Firefox 中浏览到 http://localhost:5002 时一样。相反,我得到以下信息:

【问题讨论】:

    标签: c# ssl selenium-webdriver selenium-firefoxdriver


    【解决方案1】:

    直接在 FireFoxOptions 上设置参数而不是配置文件...

    var firefoxOptions = new FirefoxOptions();
    firefoxOptions.AcceptInsecureCertificates = true;
    

    我还注意到您的 URL 不是 https,如果您想接受不安全的证书,您可能应该浏览到 https,即

    driver.Url = "https://localhost:5002/";
    

    【讨论】:

      猜你喜欢
      • 2013-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-18
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      相关资源
      最近更新 更多