Setting Firefox Preferences to Save PDFs to File Directly in Selenium

Last updated:

If your application involves downloading files, you want to include that in your functional tests too. If you, however, don't configure the Selenium Driver, the default behaviour (for the Firefox Client at least) is to open up a dialog and require that you select whether you want to download, to open and so on.

This is how you configure Firefox from within Selenium so that PDF downloads get downloaded automatically to a directory you specify (in my example, downloads go to /tmp). If you don't do this and you trigger a download from within your app, then you'll need to (manually) click on the dialogs that come up.

profile =
profile[''] = 2 #custom location
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"
profile[''] = false
profile[''] = false
profile[''] = '/tmp'
profile['pdfjs.disabled'] = true
DRIVER = Selenium::WebDriver.for :firefox , :profile => profile

Dialogue & Discussion