Selenium 在 Firefox 配置文件中禁用插件

Posted

技术标签:

【中文标题】Selenium 在 Firefox 配置文件中禁用插件【英文标题】:Selenium disable plugins in firefox profile 【发布时间】:2013-05-26 04:29:18 【问题描述】:

谁能告诉我如何使用 Java 为我的客户 firefox 配置文件禁用插件?我发现一些网站显示添加附加组件,但没有关于禁用插件的内容。

我的 Firefox 个人资料:

    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setAcceptUntrustedCertificates(true);
    firefoxProfile.setAssumeUntrustedCertificateIssuer(false);
    firefoxProfile.setPreference("browser.download.folderList",2);
    firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
    firefoxProfile.setPreference("browser.download.dir",reportFolder);
    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/pdf,application/csv,application/vnd.ms-excel");
    firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete",false);  firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete",false);
    firefoxProfile.setPreference("browser.download.manager.showWhenStartinge",false);
    firefoxProfile.setPreference("browser.download.panel.shown",false);
    firefoxProfile.setPreference("browser.download.useToolkitUI",true);
    firefoxProfile.setPreference("pdfjs.disabled", true);
    firefoxProfile.setPreference("pdfjs.firstRun", false);
driver = new FirefoxDriver(firefoxProfile);

问题是默认情况下启用了一些插件。 Adobe acrobat、google update、java、microsoft office、flash、shockwave for director 和 silverlight。

我需要禁用其中的一些,因为它们会扰乱我的测试。

【问题讨论】:

【参考方案1】:

除非您创建一个显式安装 firefox 扩展/插件的配置文件,否则 Selenium Webdriver 将创建一个空白配置文件并使用它。

您能告诉我们您使用什么代码来调用 FF 驱动程序吗?

【讨论】:

您好 Farlan 我已经用我的代码更新了这个问题。不幸的是,创建的空白配置文件确实启用了一些插件。 你能指定哪些干扰了你的测试吗? Acrobat 似乎是其中大多数的原因 尝试添加此首选项:"plugin.disable_full_page_plugin_for_types", "application/pdf" 根据您的 Firefox 版本,除了 application/pdf 之外,您可能还需要包含几个额外的 MIME 类型:firefoxProfile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml");

以上是关于Selenium 在 Firefox 配置文件中禁用插件的主要内容,如果未能解决你的问题,请参考以下文章