Sanjeev Kulkarni N
Sanjeev Kulkarni N

Reputation: 381

Watir Web driver to download file

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.

Upvotes: 1

Views: 3711

Answers (1)

coloradoblue
coloradoblue

Reputation: 625

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/

Upvotes: 2

Related Questions