I want Firefox to directly download the PDF files instead of showing them in browser. I used following settings
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.dir", "c:\tmp");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
WebDriver driver = new FirefoxDriver(firefoxProfile);
// Its just a sample URL
driver.get("http://www.energy.umich.edu/sites/default/files/pdf-sample.pdf");
On about:config
page I can see that this setting are successfully reflected also the response type is application/pdf
.
When Webdriver launches Firefox I can see following option.
It should be "Save File".
Still Firefox is showing PDF in browser. I am using Firefox 29.0.1, does the preference values have changed?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…