c# - Selenium C# Firefox 22 - 来自网络的 "silent save file"不再工作

标签 c# firefox selenium nunit selenium-webdriver

我正在使用 selenium 框架 2.33 对网页进行测试。此处的 TestCase 应验证文件的下载。

以下代码适用于 Firefox 21 及更早版本。自从更新到 FF 22 后,它就不再工作了,我还没有找到原因。

我用它来保存 tar.gz 文件,但 txt 或 CSV 文件也失败了。

安装驱动:

FirefoxProfile profile = new FirefoxProfile();
profile.AcceptUntrustedCertificates = true;
profile.SetPreference("browser.download.dir", System.Environment.GetEnvironmentVariable("TEMP"));
profile.SetPreference("browser.download.folderList", 2);
profile.SetPreference("browser.download.manager.showWhenStarting", false);
profile.SetPreference("browser.helperApps.alwaysAsk.force", false);
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "text/xml, text/csv, text/plain, text/log, application/zlib, application/x-gzip, application/x-compressed, application/x-gtar, multipart/x-gzip, application/tgz, application/gnutar, application/x-tar");
profile.SetPreference("pdfjs.disabled", true);
IWebDriver webDriver = new FirefoxDriver(profile);

测试:

webDriver.Navigate().GoToUrl("https://example.com/downloadthis.txt");

注意: 在 firefox 22 中,“about:config”存在带有给定参数的行“browser.helperApps.neverAsk.saveToDisk”。但尽管如此,“保存文件”对话框会弹出,并且在检查保存位置的预期文件时测试失败。

有没有人有这个想法或也遇到过这个?

编辑:格式化

最佳答案

好的,在用户 user1177636 的帮助下,我找到了解决方案。

Firefox 已将 .tar.gz 文件的 MIME 类型从 FF 21 更改为 22

旧:应用程序/x-gzip 新:应用程序/gzip

将设置中的行更正为:

profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "text/xml, text/csv, text/plain, text/log, application/zlib, application/x-gzip, application/x-compressed, application/x-gtar, multipart/x-gzip, application/tgz, application/gnutar, application/x-tar, application/gzip");

它再次起作用了!

THX user1177636,我赞成你的评论(如果有任何意义的话)!

关于c# - Selenium C# Firefox 22 - 来自网络的 "silent save file"不再工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17314919/

相关文章:

c# - 从 List<T> 高效地返回 IList<Interface>(避免从 List<T> 转换为 List<I>)

c# - 解析 JSON 而不抛出错误异常?

C# 列表框项目大小限制

CSS:将溢出元素变成新行

java - Selenium 火狐 - WebDriverException : Reached error page: about:certerror

java - Selenium Webdriver 警告 - 无效 token "screen"

c# - 在 DataGrid 中修剪文本时的自动工具提示

sqlite - Mozilla Firefox moz_places last_visit_date显示的时间不正确

javascript - Python Crawling Pastebin(JavaScript 呈现的网页)

java - 单击相关按钮