为什么在Firefox驱动程序中设置acceptuntrustedcertificates为true不起作用?

4
我正在开发一些Selenium测试,但遇到了一个重要问题,因为当我使用安全连接(HTTPS)测试我的网站时,我没有找到一个“真正”的解决方案。我在stackoverflow上找到的所有解决方案都已过时或无法使用:
  1. 我正在Firefox中编写Selenium脚本,但出现“不受信任的证书”
  2. 如何使用Selenium禁用Firefox的不受信任的连接警告?
  3. 使用WebDriver处理不受信任的SSL证书
我唯一的解决办法是使用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!

感谢您的帮助!


“doesn't work?” 意味着什么都没有, 请提供错误和日志。 - parik
从字面上讲,没有错误,因为当我访问我的安全页面(https)时,我遇到了页面“您的连接不安全”。这表明证书不受信任/无效。 - Mister Q
2个回答

2

是的,这是geckodriver上的一个bug。你可以在这里找到它!


1
FirefoxOptions中将AcceptInsecureCertificates属性设置为true,这个问题就得到了解决。以下是我更改后的初始化代码:
        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
        });

你把这段代码放在哪里了? - Wolfgang Blessen
@WolfgangBlessen 在 SetUp 方法中!ejoshuas-stand-with-ukraine 感谢更新 :) - Mister Q

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接