Selenium为什么为firefox驱动程序设置acceptuntrustedcertificates为true不起作用?

时间:2017-03-03 16:22:13

标签: c# selenium firefox selenium-webdriver geckodriver

我正在开发一些硒测试,我面临一个重要问题,因为当我使用安全连接( HTTPS )测试我的网站时,我没有找到“真正的”解决方案。我在stackoverflow上找到的所有解决方案都已过期或无效:

  1. I am writing a Selenium script in Firefox but I am getting "Untrusted Certificate"
  2. How to disable Firefox's untrusted connection warning using Selenium?
  3. Handling UntrustedSSLcertificates using WebDriver
  4. 我唯一的解决方法是使用github上指示的每晚mozilla版本:https://github.com/mozilla/geckodriver/issues/420

            private IWebDriver driver;
            private string baseURL;
            private FirefoxOptions ffOptions;
            private IWait<IWebDriver> wait;
    
            [SetUp]
            public void SetupTest()
            {
                ffOptions = new FirefoxOptions();
                ffOptions.BrowserExecutableLocation = @"D:\AppData\Local\Nightly\firefox.exe";
                FirefoxProfile profile = new FirefoxProfile();
                profile.AssumeUntrustedCertificateIssuer = false;
                profile.AcceptUntrustedCertificates = true;
                ffOptions.Profile = profile;            
                ffOptions.LogLevel = FirefoxDriverLogLevel.Info;
                driver = new FirefoxDriver(FirefoxDriverService.CreateDefaultService(), ffOptions, TimeSpan.FromSeconds(30));
    
                //[...]           
            }
    

    配置:

    • Firefox v47.0.1,v49.0.2,v51.0.1,v52.0b9 (我试过这些不同的版本)
    • geckodriver 0.14
    • selenium 3.1.0

    有没有人有避免使用夜间释放的解决方案?

    有关信息,由于我的互联网政策,我只能访问stackoverflow和github,请不要建议我使用chrome!

    感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

是的,它是geckodriver的一个错误。你可以找到它here

答案 1 :(得分:0)

AcceptInsecureCertificates 中将 true 属性设置为 FirefoxOptions 为我解决了这个问题。这是更改后我的初始化的样子:

        var profile = new FirefoxProfile();
        profile.DeleteAfterUse = true;
        profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", LocalURL);
        profile.SetPreference("network.automatic-ntlm-auth.allow-non-fqdn", true);
        profile.SetPreference("webdriver_accept_untrusted_certs", true);
        // Only setting this property to true did not work for me either
        profile.AcceptUntrustedCertificates = true;
        profile.AssumeUntrustedCertificateIssuer = false;

        return new FirefoxDriver(new FirefoxOptions
        {
            Profile = profile,
            // When I also added this line, it DID work
            AcceptInsecureCertificates = true
        });