简体   繁体   English

如何使用watir Webdriver下载?

[英]How can i download with watir webdriver?

Here is the code on their website but I'm not understanding what to do exactly. 这是他们网站上的代码,但我不知道该怎么做。 I'm still considerably new to Ruby. 我还是Ruby的新手。

download_directory = "#{Dir.pwd}/downloads"
download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?

profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.folderList'] = 2 # custom location
profile['browser.download.dir'] = download_directory
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf"

b = Watir::Browser.new :firefox, :profile => profile

I'm trying to download a current url as a .html file that I make the browser go to. 我正在尝试将当前网址下载为.html文件,以使浏览器进入该目录。 Please help anyway you can, Thanks :) 请随时提供帮助,谢谢:)

This is what I do: 这是我的工作:

require 'watir-webdriver'
@browser = Watir::Browser.new :firefox
@browser.goto 'www.watir.com'
filename = 'downloads/watir.html'
open(filename, 'w') { |f| f.puts @browser.html }

make sure the 'downloads' directory exists or you will get an error 确保“下载”目录存在,否则您将得到一个错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM