如何使用 Watir 6.0 下载文件 [英] How to download a file using Watir 6.0
问题描述
我正在尝试使用新的 Watir 6.0 下载 CSV 文件.我找到了 Firefox 的配置文件设置:
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
但 Firefox 50.0 不支持加载配置文件设置.我收到此错误消息:
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
我也尝试了 Chrome 的配置文件设置:
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.
因此两者都不适用于新的 Watir.有人知道用 Watir 下载文件的方法吗?
So both don't work with the new Watir. Does anyone know a way to download a file with Watir?
推荐答案
对于 Firefox,我们将在 Selenium 的下一个版本中支持它.
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
这篇关于如何使用 Watir 6.0 下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!