Your connection is not secure - using Selenium.WebDriver v.3.6.0 + Firefox v.56

前端 未结 3 1345
温柔的废话
温柔的废话 2021-01-14 03:28

I\'m writing tests with Selenium + C# and I face an important issue because I didn\'t found solution when I test my site with secure connection (HT

相关标签:
3条回答
  • 2021-01-14 03:30

    For me, the profile setting AcceptUntrustedCertificates was not enough, I also had to set option security.cert_pinning.enforcement_level. My startup looks like

    // 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);
    
    0 讨论(0)
  • 2021-01-14 03:42

    You are setting the properties on the profile. The FirefoxOptions has a property AcceptInsecureCertificates, set that to true.

    Forget the profile, this is what you want:

    var op = new FirefoxOptions
    {
        AcceptInsecureCertificates = true
    };
    
    Instance = new FirefoxDriver(op);
    
    0 讨论(0)
  • 2021-01-14 03:51

    It works for me for following settings (same as above):

    My env:

    win 7

    firefox 61.0.2 (64-bit)

    Selenium C# webdriver : 3.14.0

    geckodriver-v0.21.0-win32.zip

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

    FirefoxOptions options = new FirefoxOptions();

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

    options.AcceptInsecureCertificates = true;

    new FirefoxDriver(RelativePath,options);

    0 讨论(0)
提交回复
热议问题