如何使用Watir 6.0

时间:2016-12-16 20:32:48

标签: ruby automated-tests watir watir-webdriver ruby-watir

我正在尝试使用新的Watir 6.0下载CSV文件。我找到了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

但Firefox 50.0不支持加载配置文件设置。我收到此错误消息:

/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

我还尝试了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

但不保存文件,文件保存对话框也不会关闭。

所以两者都不适用于新的Watir。有没有人知道用Watir下载文件的方法?

1 个答案:

答案 0 :(得分:1)

对于Firefox,我们将在下一版Selenium中支持。

对于Chrome,您需要遵循代码in the documentation

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

browser = Watir::Browser.new :chrome, prefs: prefs