1

I'm trying to download a CSV file with the new Watir 6.0. I found the profile settings for Firefox:

profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = path_to_download
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv"
browser = Watir::Browser.new :firefox, :profile => profile

But Firefox 50.0 doesn't support loading profile settings. I get this error message:

/var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/remote/w3c_bridge.rb:80:in `initialize': unknown option: {:profile=>#<Selenium::WebDriver::Firefox::Profile

I tried also the profile settings for Chrome:

profile = Selenium::WebDriver::Chrome::Profile.new
profile['download.prompt_for_download'] = false
profile['download.default_directory'] = path_to_download
browser = Watir::Browser.new :chrome, :profile => Profile

but the file will not be saved and the file-save dialog will be not closed.

So both don't work with the new Watir. Does anyone know a way to download a file with Watir?

Mohsin Awan
  • 1,176
  • 2
  • 12
  • 29
Gunnar Gläser
  • 337
  • 5
  • 13

1 Answers1

1

For Firefox, we'll have that supported in the next release of Selenium.

For Chrome you need to follow the code in the documentation:

prefs = {
  download: {
    prompt_for_download: false, 
    default_directory: "/path/to/dir"
  }
}

browser = Watir::Browser.new :chrome, prefs: prefs
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
titusfortner
  • 4,099
  • 2
  • 15
  • 29
  • Is there also a possibilty to change the profile settings to display the content in the browser instead of opening a download Dialog? – Gunnar Gläser Dec 17 '16 at 06:39
  • With Google Chrome 55.0.2XXX and gnomedriver 2.25 under ubuntu it don't work. The file save dialog will be opened and doesn't close and no file is saved. – Gunnar Gläser Dec 28 '16 at 10:24