1

当我使用 ruby​​ watir 在 Firefox 浏览器中单击网页链接时:

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

文件开始下载,然后.text出现警告:“Firefox 应该如何处理这个文件”。我想禁用此警报。

4

2 回答 2

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 关于“使用 Firefox 和 Watir-WebDriver 确定要自动保存的文件 MIME 类型”的帖子。

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

于 2013-08-02T12:50:27.710 回答
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
于 2014-03-28T15:03:02.727 回答