How to download a file using Watir 6.0

ぃ、小莉子 提交于 2019-12-23 03:45:08

问题


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?


回答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


来源:https://stackoverflow.com/questions/41192041/how-to-download-a-file-using-watir-6-0

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