如何使用watir单击链接时在Firefox中处理下载警报?

时间:2013-08-02 12:27:19

标签: firefox watir watir-webdriver

当我点击firefox浏览器中带有ruby watir的网页链接时:

ie.input(:id, "c_ImageButton_Text").click

.text文件开始下载,然后出现一条警告:“Firefox应该对此文件做什么”。我想禁用此警报。

2 个答案:

答案 0 :(得分:2)

尝试将配置文件设置为始终下载特定文件类型。这可以通过设置browser.helperApps.neverAsk.saveToDisk属性来完成。

例如,要始终下载pdf:

profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"

b = Watir::Browser.new :firefox, :profile => profile

该属性是逗号分隔的MIME类型列表。有关如何确定适用的MIME类型的详细信息,请参阅Scott Alister关于“Determining file MIME types to autosave using Firefox & Watir-WebDriver”的帖子。

请注意,配置此设置与转到Firefox的选项>的用户相同。 “应用程序”选项卡,允许在每种文件类型上指定操作。

答案 1 :(得分:1)

我成功尝试了Justin Ko的解决方案,这对我来说很好..我想你的情况,你正在尝试.txt扩展..对于那种情况..解决方案将是这样的:

始终下载txt:

profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv"

b = Watir::Browser.new :firefox, :profile => profile