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?
Chosen Solution. Click the Firefox button, go to Options | Options | General and in the Downloads menu, checkmark the option "Always ask me where to save files". Click the Firefox button, go to Options | Options | General and in the Downloads menu, checkmark the option "'''Always ask me where to save files'''".
On the right, go to the Content section, and click on Additional content settings. Click on PDF documents. On the next page, turn on (enable) the Download PDF files instead of automatically opening them in Chrome option. You are done.
Go to Preferences->Applications and see what actions are assigned for PDF and Portable Document Format. It should be "preview in firefox" for it to open directly in Firefox.
The same as above for a remote Firefox Webdriver using Python Selenium:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", "/data");
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
profile.set_preference("pdfjs.disabled", True)
profile.set_preference("plugin.scan.Acrobat", "99.0")
profile.set_preference("plugin.scan.plid.all", False)
driver = webdriver.Remote(
browser_profile=profile,
command_executor='http://localhost:4444/wd/hub',
desired_capabilities=options.to_capabilities()
)
driver.get("https://www.ti.com/lit/ds/symlink/sa555.pdf");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With