PSA: Downloading PDF Files With New Firefox

78 views
Skip to first unread message

Eachus Lonny

unread,
May 22, 2013, 7:55:33 PM5/22/13
to watir-...@googlegroups.com

As you may know, the latest version of Firefox has a JavaScript .pdf viewer. This can cause issues when you want to download a .pdf file.

To eliminate problems with the Firefox .pdf viewer in Watir, disable "pdfjs" in Firefox preferences, like so:

      profile['pdfjs.disabled'] = true

Here it is in a complete Firefox profile set up for downloading, which you must create before instantiating the Watir browser:

      download_directory = "your_download_path"
      download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
      profile = Selenium::WebDriver::Firefox::Profile.new
      profile['browser.download.dir']        = download_directory
      profile['browser.download.folderList'] = 2
      profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"

      browser = Watir::Browser.new :ff, :profile => profile


I hope this saves some people a bit of research.


Lonny Eachus
============


Eachus Lonny

unread,
May 23, 2013, 12:15:14 PM5/23/13
to watir-...@googlegroups.com

In my message yesterday I inadvertently omitted from the example Firefox profile the very line I was trying to point out.

If you want to disable the PDF viewer in Firefox, the corrected code is as follows:

download_directory = "your_download_path"
download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.dir'] = download_directory
profile['browser.download.folderList'] = 2profile['pdfjs.disabled'] = true
browser = Watir::Browser.new :ff, :profile => profile


Lonny Eachus
============





Eachus Lonny

unread,
May 23, 2013, 12:15:15 PM5/23/13
to watir-...@googlegroups.com

Eachus Lonny

unread,
May 24, 2013, 11:24:29 AM5/24/13
to watir-...@googlegroups.com

Wow. Talk about typing problems.

Something happened with the formatting of the "corrected" code I sent yesterday. AND somehow the email got sent twice.

So here's a third try. I hope it comes out okay this time. Code for downloading PDF files in the new Firefox:

download_directory = "your_download_path"
download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.dir'] = download_directory
profile['browser.download.folderList'] = 2
profile['pdfjs.disabled'] = true # <-- This is the added line.
Reply all
Reply to author
Forward
0 new messages