FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.dir","c:\\downloads");
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/pdf,application/x-pdf");
我正在使用以上代码pdf的MIME是我认为正确application/pdf,application/x-pdf
然后使用它来
WebDriver driver = new FirefoxDriver(firefoxProfile);
driver.navigate().to("Website");
但是我无法理解我的代码的问题,因为Firefox仍然显示对话框
答案 0 :(得分:2)
试试这个:
firefoxProfile.setPreference("pdfjs.disabled", true);
答案 1 :(得分:1)
尝试将MIME类型设置为:
application/octet-stream