带有 watir webdriver 的 Firefox 4:需要使用 helperApps.neverAsk 的帮助来保存 CSV 而无需提示
我学习了如何将 Firefox 4 与 watir 和 webdriver(在 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)
我尝试在下面的示例中执行的操作是将 CSV 文件设置为始终下载到特定目录,从不打开。 上面的代码成功地将所有文件设置为自动下载到指定目录,但是设置 browser.helperApps.neverAsk.saveToDisk
没有效果:我仍然遇到打开/保存问题。 脚本运行后,Firefox 窗口仍然打开,我输入 URL about:config。 我可以看到 browser.helperApps.neverAsk.saveToDisk
已正确设置为 application.csv
,但在 firefox/options/options/applications 中我没有看到以下条目CSV 文件。 看起来真正有效的菜单设置并没有真正与 about:config 设置绑定。 我做错了什么?
I learned how to use Firefox 4 with watir and webdriver (on Win7 x64), setting profile items. Example:
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)
What I try to do with the example below, is setting CSV files to be always downloaded to a specific directory, never opened.
The code above succeeds in setting all the files automatically downloaded to the specified directory, but setting browser.helperApps.neverAsk.saveToDisk
has no effect: I still get the open/save question.
After the script runs, the Firefox window is still open, and I enter the URL about:config.
I can see that browser.helperApps.neverAsk.saveToDisk
was correctly set to application.csv
, but in firefox/options/options/applications I don't see the entry for CSV files.
It seems that the menu setting, that is really effective, is not really bound with the about:config setting.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经为您做了一些测试,遗憾的是 CSV 文件似乎没有标准的内容类型。您可以尝试传递以逗号分隔的内容类型列表,希望其中之一适合您。对我来说,是 application/octet-stream 做到了这一点......
I've done some testing of this for you, unfortunately there doesn't seem to be a standard content-type for CSV files. You can try passing a comma separated list of content-types, hopefully one of those work for you. For me it was application/octet-stream that did the trick...
在 Firefox 6+ 中,如果不专门设置 'browser.download.folderList' 值,我无法使其工作:
请参阅: http://watirwebdriver.com/browser-downloads/
In Firefox 6+, I couldn't get this to work without specifically setting the 'browser.download.folderList' value:
See: http://watirwebdriver.com/browser-downloads/