FirefoxProfile设置被忽略

时间:2016-11-28 14:56:45

标签: c# selenium-webdriver firefox-marionette

将Selenium WebDriver 3.0.1.0与Marionette和geckodriver 0.11.1以及C#的Firefox 50一起使用。我使用了由此ObsoleteAttribute驱动的FirefoxOptions

  

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尚未准备好使用?

2 个答案:

答案 0 :(得分:0)

我不确定实际上是否忽略了配置文件设置:

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

答案 1 :(得分:0)

此操作很正常,可避免访问SSL证书错误页面:

    public static FirefoxOptions FfOptions()

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

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