如何使用Watir 6.0下载文件 [英] How to download a file using Watir 6.0

查看:99
本文介绍了如何使用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.

对于Chrome,您需要遵循文档中的代码 :

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆