带有 watir webdriver : Need help using helperApps. 的 Firefox 4 neverAsk 不提示保存 CSV

标签 firefox watir webdriver firefox4 watir-webdriver

我学习了如何将 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 设置绑定(bind)。
我究竟做错了什么?

最佳答案

我已经为你做了一些测试,不幸的是,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"

关于带有 watir webdriver : Need help using helperApps. 的 Firefox 4 neverAsk 不提示保存 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5473354/

相关文章:

javascript - 是:after working supposed to work when applied to an input?

javascript - Firefox jquery position() 关闭 1px

jQuery 适用于 Firefox 但不适用于 Chrome

ruby - 如何使用 watir 将图像保存在 blob 字段中?

javascript - 在列表框边缘浏览器中选择多个选项 ruby​​ selenium webdriver

ruby - 重新打开 Ruby 类的奇怪问题

java - 在文本区域插入非常大的字符串时,浏览器不支持 : selenium :java

java - java中的Selenium下拉问题

jquery - 在 Firefox 中使用 Jquery $.post 时出现 406 Not Acceptable 错误,但在 Safari 或 Chrome 中则不然

javascript - 类型错误 : Cannot read property 'textToBePresentInElementValue' of undefined