Ruby interacting with Selenium to control Firefox open/save dialog

限于喜欢 提交于 2019-12-25 08:59:23

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/42958611/ruby-interacting-with-selenium-to-control-firefox-open-save-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!