0

我在使用框架 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 类型是 application/iso-image 或 application/octet-stream 但它不起作用。

感谢大家的回答。

4

1 回答 1

0

您可以在 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-image
于 2016-08-30T15:14:10.577 回答