【问题标题】:Your connection is not secure - using Selenium.WebDriver v.3.6.0 + Firefox v.56您的连接不安全 - 使用 Selenium.WebDriver v.3.6.0 + Firefox v.56
【发布时间】:2018-04-18 10:48:11
【问题描述】:

我正在使用 Selenium + C# 编写测试,但我遇到了一个重要问题,因为我在使用安全连接 (HTTPS) 测试我的网站时没有找到解决方案.我在 stackoverflow 上找到的所有解决方案都已过时或不起作用。 我试图从以下问题中练习所有解决方案: Selenium Why setting acceptuntrustedcertificates to true for firefox driver doesn't work?

但他们并没有帮我解决问题 也不是使用 Nightly FireFox 的解决方案。 不过,当 selenium 加载 Firfox 浏览器时,我看到页面:“您的连接不安全”。

配置:

  • 火狐 v56.0
  • Selenium.Firefox.WebDriver v0.19.0
  • Selenium.WebDriver v3.6.0

我的代码是:

                    FirefoxOptions options = new FirefoxOptions();
                    FirefoxProfile profile = new FirefoxProfile();
                    profile.AcceptUntrustedCertificates = true;
                    profile.AssumeUntrustedCertificateIssuer = false;
                    options.Profile = profile;
                    driver = new FirefoxDriver(FirefoxDriverService.CreateDefaultService() , options , TimeSpan.FromSeconds(5));
                    Drivers.Add(Browsers.Firefox.ToString() , driver);

感谢您的帮助!

在这里更新我的问题:

注意 1: 致将我的问题标记为该问题重复的任何人:

Firefox selenium webdriver gives “Insecure Connection” 我认为这是同样的问题,但我需要 C# 的解决方案,我尝试将您的 JAVA 代码与我上面的代码匹配

首先,我将以下语句更改为 TRUE:

     profile.AssumeUntrustedCertificateIssuer = true;

其次,我创建新的 FF 配置文件(“AutomationTestsProfile”) 并尝试使用它:

尝试1:

       FirefoxProfile profile = new FirefoxProfileManager().GetProfile("AutomationTestsProfile");

尝试 2:

       FirefoxProfile profile = new FirefoxProfile("AutomationTestsProfile");

我运行 2 个选项,但问题仍然存在。

注意 2: 我附上了我的问题的屏幕截图,当驱动程序尝试在登录页面上输入文本到用户名时出现。

我注意到,当我使用 FF 打开我的网站时,Firefox 在地址栏中显示一个带有红色删除线的锁定图标 红色删除线图标,

但在用户名文本框附近没有出现味精:

“此连接不安全。此处输入的登录信息可能会被盗用。了解更多”(正如您在重复问题中所写),

那么也许有不同的问题?

【问题讨论】:

    标签: c# firefox selenium-webdriver ssl-certificate


    【解决方案1】:

    您正在设置配置文件的属性。 FirefoxOptions 有一个属性 AcceptInsecureCertificates,将其设置为 true。

    忘记个人资料,这就是你想要的:

    var op = new FirefoxOptions
    {
        AcceptInsecureCertificates = true
    };
    
    Instance = new FirefoxDriver(op);
    

    【讨论】:

    • 感谢 Jota,多年来一直在寻找这个解决方案!
    • 谢谢!有用。但我不明白为什么我需要将其设置为 true,如果在 FirefoxProfile 类文档中他们写“默认设置为 true”?
    【解决方案2】:

    它适用于以下设置(与上面相同):

    我的环境:

    赢7

    火狐 61.0.2(64 位)

    Selenium C# 网络驱动程序:3.14.0

    geckodriver-v0.21.0-win32.zip

    ================================

    FirefoxOptions 选项 = 新的 FirefoxOptions();

    options.BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";

    options.AcceptInsecureCertificates = true;

    新的 FirefoxDriver(RelativePath,options);

    【讨论】:

      【解决方案3】:

      对我来说,配置文件设置AcceptUntrustedCertificates 是不够的,我还必须设置选项security.cert_pinning.enforcement_level。我的创业公司看起来像

      // no idea why FirefoxWebDriver needs this, but it will throw without
      // https://stackoverflow.com/questions/56802715/firefoxwebdriver-no-data-is-available-for-encoding-437
      CodePagesEncodingProvider.Instance.GetEncoding(437);
      Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
      
      var service = FirefoxDriverService.CreateDefaultService(Environment.CurrentDirectory);
      service.FirefoxBinaryPath = Config.GetConfigurationString("FirefoxBinaryPath"); // path in appsettings
      
      var options = new FirefoxOptions();
      options.SetPreference("security.cert_pinning.enforcement_level", 0);
      options.SetPreference("security.enterprise_roots.enabled", true);
      
      var profile = new FirefoxProfile()
      {
          AcceptUntrustedCertificates = true,
          AssumeUntrustedCertificateIssuer = false,
      };
      options.Profile = profile;
      
      var driver = new FirefoxDriver(service, options);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-05-08
        • 1970-01-01
        • 2017-07-26
        • 2017-11-26
        • 1970-01-01
        • 1970-01-01
        • 2017-07-12
        相关资源
        最近更新 更多