Javascript 使用量角器在Firefox上下载文件

Javascript 使用量角器在Firefox上下载文件,javascript,firefox,selenium-webdriver,jasmine,protractor,Javascript,Firefox,Selenium Webdriver,Jasmine,Protractor,我需要在Firefox上下载一个带有量角器的zip文件。 单击下载链接,弹出Windows对话框,要求打开/保存文件。那我该怎么处理呢。我需要将哪些参数传递给驱动程序? 用chrome我可以用它 下载:{ “提示下载”:false }, 但是我应该如何处理firefox。问题是-您无法通过量角器/selenium操作“另存为…”对话框。首先,您应该避免打开它,让firefox自动下载指定mime类型的文件——在您的情况下是application/zip 换句话说,您需要使用以下自定义设置启动Fi

我需要在Firefox上下载一个带有量角器的zip文件。 单击下载链接,弹出Windows对话框,要求打开/保存文件。那我该怎么处理呢。我需要将哪些参数传递给驱动程序? 用chrome我可以用它 下载:{ “提示下载”:false },

但是我应该如何处理firefox。

问题是-您无法通过量角器/selenium操作“另存为…”对话框。首先,您应该避免打开它,让firefox自动下载指定mime类型的文件——在您的情况下是
application/zip

换句话说,您需要使用以下自定义设置启动Firefox:


这里我们基本上是说:Firefox,请自动下载zip文件,无需请求进入
/path/to/save/downloads
目录。

@alecxe我们如何验证文件是否已下载?@Nick当然,等待下载,以下是工作示例:。@alecxe文件默认下载到“下载”中,我将其配置为指向相对路径,但它仍然下载到默认位置,非常感谢您的帮助。。。makeFirefoxProfile({“browser.download.folderList”:2,“browser.download.dir”:“./e2eConf/conf_Files/”,“browser.helperApps.neverAsk.saveToDisk”:“application/x-binary”})@alecxe,难道不可能使用类似executeScript和window.accept()的东西来与“另存为”交互吗?人们如何告诉Internet Explorer不要问“是否要保存…”
var q = require("q");
var FirefoxProfile = require("firefox-profile");

var makeFirefoxProfile = function(preferenceMap, specs) {
    var deferred = q.defer();
    var firefoxProfile = new FirefoxProfile();

    for (var key in preferenceMap) {
        firefoxProfile.setPreference(key, preferenceMap[key]);
    }

    firefoxProfile.encoded(function (encodedProfile) {
        var capabilities = {
            browserName: "firefox",
            firefox_profile: encodedProfile,
            specs: specs
        };

        deferred.resolve(capabilities);
    });
    return deferred.promise;
};

exports.config = {
    getMultiCapabilities: function() {
        return q.all([
            makeFirefoxProfile(
                {
                    "browser.download.folderList": 2,
                    "browser.download.dir": "/path/to/save/downloads",
                    "browser.helperApps.neverAsk.saveToDisk": "application/zip"
                },
                ["specs/*.spec.js"]
            )
        ]);
    },

    // ...
}