【问题标题】:How to set Mozilla Firefox to doesn't open manager download with .iso file?如何将 Mozilla Firefox 设置为不使用 .iso 文件打开管理器下载?
【发布时间】:2016-08-30 14:44:42
【问题描述】:

我在使用框架 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 但它不起作用。

感谢大家的回答。

【问题讨论】:

    标签: java selenium firefox vaadin test-bench


    【解决方案1】:

    您可以在 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
    

    【讨论】:

    猜你喜欢
    • 2014-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 2021-03-08
    • 1970-01-01
    相关资源
    最近更新 更多