在使用框架Vaadin测试平台和Selenium库时,我遇到了一个问题。对于我的测试,我需要告诉Mozilla Firefox浏览器31.0版本,当我尝试下载.iso文件时,不要打开下载管理器对话框。我希望下载在我设置的路径中自动开始。举个JAVA代码的例子,我在apache tomcat 1.8上使用jdk 1.8,我的操作系统是Windows 8:
public static RemoteWebDriver getFirefoxDriver(String pathDownloadFile) {
final FirefoxProfile firefoxProfile = new FirefoxProfile();
final DesiredCapabilities capability = new DesiredCapabilities();
firefoxProfile.setPreference("browser.download.dir", pathDownloadFile);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.defaultFolder", pathDownloadFile);
firefoxProfile.setPreference("pdfjs.disabled", true);
firefoxProfile.setPreference("plugin.scan.plid.all", false);
firefoxProfile.setPreference("plugin.scan.Acrobat", "99.0");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/pdf,application/octet-stream,application/xml,text/csv,application/zip,application/vnd.pdf,"
+ "application/x-pdf,application/pkcs7-mime,application/x-pkcs7-mime,application/pkcs7-signature,text/plain,"
+ "application/iso-image");
firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
firefoxProfile.setEnableNativeEvents(false);
capability.setBrowserName("firefox");
capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
WebDriver driver = new RemoteWebDriver(testingbotdotcom, capability);
return driver;
}这是firefox配置文件的设置。我认为问题出在mime类型上,但我在每个论坛上都看到.iso文件的mime类型是应用程序/iso-image或应用程序/八位字节流,但它不起作用。
感谢所有人的回答。
发布于 2016-08-30 23:14:11
您可以在linux上使用以下curl命令确定mimetype
curl -I "http://ftp.uni-erlangen.de/mirrors/ubuntu-releases/16.04/ubuntu-16.04.1-desktop-amd64.iso" | grep "Content-Type"它会返回
Content-Type: application/x-iso9660-imagehttps://stackoverflow.com/questions/39230634
复制相似问题