如何使用selenium web driver firefox profile禁用下载弹出窗口?

时间:2016-10-26 12:16:50

标签: selenium firefox selenium-webdriver webdriver selenium-firefoxdriver

使用firefox配置文件是:

protected FirefoxProfile firefoxProfile() {
    fxProfile.setPreference("browser.download.folderList", 2);
    fxProfile.setPreference("browser.download.dir", path);
    fxProfile.setPreference("browser.download.manager.alertOnEXEOpen", false);
    fxProfile.setPreference("browser.helperApps.neverAsk.openFile", "text/csv,application/csv,application/text");
    fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/csv,application/text");
    fxProfile.setPreference("browser.download.manager.showWhenStarting", false);
    fxProfile.setPreference("browser.download.manager.focusWhenStarting", false);
    fxProfile.setPreference("browser.download.useDownloadDir", true);
    fxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
    fxProfile.setPreference("browser.download.manager.alertOnEXEOpen", false);
    fxProfile.setPreference("browser.download.manager.closeWhenDone", true);
    fxProfie.setPreference("browser.download.manager.showAlertOnComplete", false);
    fxProfile.setPreference("browser.download.manager.useWindow", false);
    fxProfile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
    fxProfile.setPreference("pdfjs.disabled", true);
}

(我仍然可以在浏览器中看到弹出窗口)here

在此处使用个人资料初始化firefox驱动程序:

FirefoxBinary ffBinary = new FirefoxBinary();
ffBinary.setTimeout(TimeUnit.SECONDS.toMillis(180));
internalDriver = new FirefoxDriver(ffBinary, firefoxProfile());

0 个答案:

没有答案