Watir Web驱动程序下载文件 [英] Watir Web driver to download file

查看:152
本文介绍了Watir Web驱动程序下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写Ruby脚本以自动化使用Watir Web驱动程序从文件列表中下载文件。自动弹出窗口和目录选择器的任何指针或方法将文件保存到一个位置?谢谢。

I'm writing Ruby script to automate Downloading files from a list of files using Watir web driver. Any pointers or approaches on Automating Popping up of Window and Directory Chooser to save the file into a location? Thanks.

推荐答案

更改默认的Watir首选项下载位置

change default Watir preferences for download location

chrome

profile = Selenium::WebDriver::Chrome::Profile.new
download_dir = File.join(Rails.root, 'lib', 'assets')
profile['download.default_directory'] = download_dir
profile['download.prompt_for_download'] = false
@b = Watir::Browser.new :chrome, :profile => profile

for firefox

for firefox

profile = Selenium::WebDriver::Firefox::Profile.new    
download_dir = File.join(Rails.root, 'lib', 'assets')
profile['browser.download.dir'] = download_dir
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf"
@b = Watir::Browser.new. :firefox, :profile => profile

注意:可以轻松地从您的rails中访问Rails.root / lib文件夹应用程序,您需要将此代码或类似的东西添加到您的config / application.rb文件中:

note: to be be able to access the Rails.root/lib folder easily from within your rails app, you'll need to add this code or something like it to your config/application.rb file:

config.autoload_paths += Dir["#{config.root}/lib/**/"]

信息: http://watir.github.io/docs/browser-downloads/

这篇关于Watir Web驱动程序下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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