Watir Web driver to download file

2019-04-16 12:17发布

I'm writing Ruby script to automate Downloading files from a list of files using Watir web driver. Any pointers or approaches on Automating Popping up of Window and Directory Chooser to save the file into a location? Thanks.

1条回答
啃猪蹄的小仙女
2楼-- · 2019-04-16 12:50

change default Watir preferences for download location

for chrome

profile = Selenium::WebDriver::Chrome::Profile.new
download_dir = File.join(Rails.root, 'lib', 'assets')
profile['download.default_directory'] = download_dir
profile['download.prompt_for_download'] = false
@b = Watir::Browser.new :chrome, :profile => profile

for firefox

profile = Selenium::WebDriver::Firefox::Profile.new    
download_dir = File.join(Rails.root, 'lib', 'assets')
profile['browser.download.dir'] = download_dir
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf"
@b = Watir::Browser.new. :firefox, :profile => profile

note: to be be able to access the Rails.root/lib folder easily from within your rails app, you'll need to add this code or something like it to your config/application.rb file:

config.autoload_paths += Dir["#{config.root}/lib/**/"]

for more information: http://watir.com/guides/downloads/

查看更多
登录 后发表回答