car*_*reo 4 firefox webdriver watir firefox4 watir-webdriver
我学会了如何使用带有watir和webdriver的Firefox 4(在Win7 x64上),设置配置文件项目.例:
profile = Selenium::WebDriver::Firefox::Profile.new
profile["browser.download.useDownloadDir"] = true
profile["browser.download.dir"] = 'D:\\FirefoxDownloads'
profile["browser.helperApps.neverAsk.saveToDisk"] = "application/csv"
driver = Selenium::WebDriver.for :firefox, :profile => profile
browser = Watir::Browser.new(driver)
Run Code Online (Sandbox Code Playgroud)
我尝试使用下面的示例,将CSV文件设置为始终下载到特定目录,从不打开.上面的代码成功设置了自动下载到指定目录的所有文件,但设置browser.helperApps.neverAsk.saveToDisk
无效:我仍然得到打开/保存问题.脚本运行后,Firefox窗口仍然打开,我输入关于:config的URL.我可以看到它browser.helperApps.neverAsk.saveToDisk
被正确设置为application.csv
,但在firefox/options/options/applications中我没有看到CSV文件的条目.看起来真正有效的菜单设置并没有真正与about:config设置绑定.我究竟做错了什么?
小智 11
我已经为你做了一些测试,不幸的是,似乎没有标准的CSV文件内容类型.您可以尝试传递逗号分隔的内容类型列表,希望其中一个适合您.对我来说,应用程序/八位字节流做了诀窍......
require 'watir-webdriver'
require 'selenium-webdriver'
profile = Selenium::WebDriver::Firefox::Profile.new
profile["browser.download.useDownloadDir"] = true
profile["browser.download.dir"] = '/tmp'
profile["browser.helperApps.neverAsk.saveToDisk"] = "text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream"
driver = Selenium::WebDriver.for :firefox, :profile => profile
browser = Watir::Browser.new(driver)
browser.goto "http://altentee.com/test/test.csv"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3219 次 |
最近记录: |