【问题标题】:FirefoxProfile settings are being ignoredFirefoxProfile 设置被忽略
【发布时间】:2016-11-28 14:56:45
【问题描述】:

将 Selenium WebDriver 3.0.1.0 与 Marionette 和 geckodriver 0.11.1 以及来自 C# 的 Firefox 50 一起使用。我使用了 FirefoxOptions 受此 ObsoleteAttribute 的启发:

FirefoxDriver 不应使用 FirefoxBinary 对象构造。 请改用 FirefoxOptions。

代码是:

FirefoxOptions fo = new FirefoxOptions();
firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("browser.download.folderList", 2);
firefoxProfile.SetPreference("browser.download.dir", DOWNLOAD_FOLDER);
firefoxProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
firefoxProfile.SetPreference("browser.startup.homepage_override.mstone", "ignore");
firefoxProfile.SetPreference("trustAllSSLCertificates", true);
firefoxProfile.AcceptUntrustedCertificates = true;

fo.Profile = firefoxProfile;
driver = new FirefoxDriver(fo);

在我看来,就像指定的 firefoxProfile 根本没有被使用一样,出现 SSL 证书错误,并且无论配置文件设置如何,都会显示下载对话框。我认为它不会因为this bug 而忽略 SSL 证书错误,但看起来所有配置文件设置都被忽略了。

如何使配置文件设置生效? (这样就不会出现下载对话框并忽略 SSL 错误)

该代码在切换到 Marionette 之前有效,看起来 Marionette 尚未准备好使用?

【问题讨论】:

  • 我已经切换回 IceDragon 和 Selenium 2.53,一切都恢复正常了。

标签: c# selenium-webdriver firefox-marionette


【解决方案1】:

我不确定配置文件设置是否真的被忽略了:

  1. 您应该检查MIME 要下载的文件类型。真的是text/csv吗?
  2. 没有trustAllSSLCertificates 这样的偏好。我想你需要firefoxProfile.SetPreference("security.ssl.enable_ocsp_stapling", false);

【讨论】:

  • 代码在切换到 Marionette 之前有效。但我会尝试 2,谢谢。
  • 设置"security.ssl.enable_ocsp_stapling", false 没有区别。
【解决方案2】:

这可以顺利避免访问 SSL 证书错误页面:

    public static FirefoxOptions FfOptions()

            {
                FirefoxOptions option = new FirefoxOptions();
                option.AcceptInsecureCertificates = true;
                return option;
            }

    public static IWebDriver driver = new FirefoxDriver(FfOptions());

【讨论】:

  • 我只能在切换回 Marionette 后才能验证这一点,但我想它多年来已经有所改善。
猜你喜欢
  • 2019-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多