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

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

问题描述

我在写Ruby脚本来下载文件使用的Watir网络驱动程序文件的列表自动化。任何指针或自动化膨化接近了窗口和目录选择的保存文件到一个位置?谢谢你。

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 preferences下载位置

change default Watir preferences for download location

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

针对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文件夹,你需要这样code或类似的东西添加到您的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://watirwebdriver.com/browser-downloads/

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

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