如何使用watir webdriver在firefox中禁用下载窗口?

如何使用watir webdriver在firefox中禁用下载窗口?,firefox,selenium,watir,watir-webdriver,Firefox,Selenium,Watir,Watir Webdriver,我不想在Firefox或IE中处理下载窗口。我想在没有任何下载窗口的情况下自动下载excel文件。我曾尝试为Firefox设置几个配置参数,但没有成功。 在我的测试中,我试图下载excel文件 profile = Selenium::WebDriver::Firefox::Profile.new profile['browser.download.lastDir'] = 'C:\\Downloads' profile['browser.download.folderList'] = 2 prof

我不想在Firefox或IE中处理下载窗口。我想在没有任何下载窗口的情况下自动下载excel文件。我曾尝试为Firefox设置几个配置参数,但没有成功。 在我的测试中,我试图下载excel文件

profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.lastDir'] = 'C:\\Downloads'
profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = 'C:\\Downloads'
profile['download.prompt_for_download'] = false
profile['browser.download.manager.showWhenStarting'] = false
profile['browser.download.manager.addToRecentDocs'] = true

profile['browser.download.manager.useWindow'] = false
profile['browser.download.useDownloadDir'] = true
profile['browser.download.show_plugins_in_list'] = true
profile['browser.download.manager.openDelay'] = 100000
profile['browser.download.animateNotifications'] = false

driver = Watir::Browser.new :firefox, :profile => profile
当脚本对下载按钮执行单击操作时,浏览器仍显示下载窗口

目前,我正在Windows-7(64位)上使用Firefox 35.0.1。根据,您应该使用
浏览器.helperApps.neverAsk.saveToDisk
首选项来实现这一点。值定义为

以逗号分隔的MIME类型列表,无需询问即可保存到磁盘 使用什么打开文件。默认值为空字符串

我不太擅长Ruby,但它可能看起来像

profile["browser.helperApps.neverAsk.saveToDisk"] = "text/plain, application/octet-stream"
只需使用正确的MIME类型


我也找到了答案