Solution to download pdf files automatically in firefox 20+ version using Selenium webdriver or Watir webdriver
Description:
I have tried to save PDF files automatically using the below link — http://watirwebdriver.com/browser-downloads/ and I have followed the same as per the mentioned page and reference website. But still the firefox browser not downloaded PDF files automatically.
Reason:
In Firefox latest versions, They have added new function called as ‘Portable Document Format’ which causes the issue
Solution:
Please try the below code for latest firefox versions.
download_directory =
"#{Dir.pwd}/downloads"
download_directory.gsub!(
"/"
,
"\\"
)
if
Selenium::WebDriver::Platform.windows?
profile = Selenium::WebDriver::Firefox::Profile.
new
profile[
'browser.download.folderList'
] =
2
# custom location
profile[
'browser.download.dir'
] = download_directory
profile[
'browser.helperApps.neverAsk.saveToDisk'
] =
"text/csv,application/pdf"
profile[‘pdfjs.disabled’] = true
profile[‘pdfjs.firstRun’] = false
b = Watir::Browser.
new
:firefox
,
:profile
=> profile
profile[‘pdfjs.firstRun’] = false