火狐4与watir webdriver:需要帮助使用helperApps.neverAsk来保存CSV而不提示 [英] Firefox 4 with watir webdriver: Need help using helperApps.neverAsk to save CSV without prompting

查看:208
本文介绍了火狐4与watir webdriver:需要帮助使用helperApps.neverAsk来保存CSV而不提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学会了如何在watir和webdriver(Win7 x64)上使用Firefox 4,设置配置文件项目。例子:

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)

我试着做的以下面的例子,是设置CSV文件总是下载到一个特定的目录,从来没有打开。
上面的代码成功地将所有文件自动下载到指定的目录,但设置 browser.helperApps.neverAsk.saveToDisk 没有任何作用:我仍然得到打开/保存问题。
脚本运行后,Firefox窗口仍处于打开状态,并输入有关config:的URL。
我可以看到 browser.helperApps.neverAsk.saveToDisk 被正确设置为 application.csv ,但在Firefox /选项/选项/应用程序我没有看到CSV文件的条目。
似乎菜单设置,这真的很有效,并没有真正绑定about:config设置。
我在做什么错误?

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?

推荐答案

我已经为你做了一些测试,不幸的是,似乎是CSV文件的标准内容类型。你可以尝试传递一个逗号分隔的内容类型列表,希望其中的一个为你工作。对我来说,它是应用程序/八位字节流,做了伎俩... ... $ / b>

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...

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"

这篇关于火狐4与watir webdriver:需要帮助使用helperApps.neverAsk来保存CSV而不提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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