0

Capybara.register_driver :session do |app| profile = Selenium::WebDriver::Firefox::Profile.new Capybara::Selenium::Driver.new app, :profile => profile end

What do I add here to get my ruby scripts to tell Selenium (I am running on a MAC OS El Capitan) to interact with the Firefox Open/Save dialog box such that it opens a PDF or DOC file automatically instead of prompting me with the dialog box which requires manual intervention?

Doug M
  • 1
  • 2
  • I don't know what do you want, any more detail? – Hsiu Chuan Tsao Mar 22 '17 at 18:01
  • Possible duplicate of [Access to file download dialog in Firefox](http://stackoverflow.com/questions/1176348/access-to-file-download-dialog-in-firefox) – max pleaner Mar 22 '17 at 18:26
  • I looked at the one link above but it is hard for me to parse through lots of answers (some of which aren't relevant). I want to know what ruby code I need to add to the statements above such that when the dialog box comes up, I can choose whether to open the pdf in the browser with a plug-in or to save the file away. – Doug M Mar 22 '17 at 19:24

1 Answers1

0

You can't interact with the Open/Save dialog box using selenium-webdriver with firefox. However, you can set preferences in your driver to make the dialog box never appear and a default behavior to just happen. Something like

Capybara.register_driver :session do |app|
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile['browser.download.dir'] = "~/Downloads"
  # Adjust below to match the type of file reported
  profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf, application/octet-stream" 
  Capybara::Selenium::Driver.new app, :profile => profile
end

should cause it to always download the files without prompting. You can similarly set the 'browser.helperApps.neverAsk.openFile' profile setting to have specific types of files always be opened.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • It still gives me a dialog box when trying to open a PDF file. Capybara.default_driver = :selenium Capybara.register_driver :selenium do |app| profile = Selenium::WebDriver::Firefox::Profile.new profile['browser.download.dir'] = "~/Downloads" profile['browser.helperApps.neverAsk.saveToDisk'] = "application/doc, application/pdf, application/octet-stream" Capybara::Selenium::Driver.new app, :profile => profile end – Doug M Apr 07 '17 at 21:49
  • Any good reference to the man pages for the command above in your answer would be great too as well as a description of a browser profile would be appreciated. Thank you. – Doug M Apr 07 '17 at 21:49