带有 watir webdriver 的 Firefox 4:需要使用 helperApps.neverAsk 的帮助来保存 CSV 而无需提示

发布于 2024-10-27 21:11:50 字数 828 浏览 4 评论 0原文

我学习了如何将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘和柠 2024-11-03 21:11:50

我已经为您做了一些测试,遗憾的是 CSV 文件似乎没有标准的内容类型。您可以尝试传递以逗号分隔的内容类型列表,希望其中之一适合您。对我来说,是 application/octet-stream 做到了这一点......

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"

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"
两相知 2024-11-03 21:11:50

在 Firefox 6+ 中,如果不专门设置 'browser.download.folderList' 值,我无法使其工作:

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/csv"
b = Watir::Browser.new :firefox, :profile => profile

请参阅: http://watirwebdriver.com/browser-downloads/

In Firefox 6+, I couldn't get this to work without specifically setting the 'browser.download.folderList' value:

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/csv"
b = Watir::Browser.new :firefox, :profile => profile

See: http://watirwebdriver.com/browser-downloads/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文