我正在编写Ruby脚本以自动化使用Watir Web驱动程序从文件列表下载文件。自动弹出窗口和目录选择器以将文件保存到某个位置的任何指针或方法?感谢。
答案 0 :(得分:2)
更改下载位置的默认Watir偏好设置
for 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
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文件中:
config.autoload_paths += Dir["#{config.root}/lib/**/"]