I am trying to download an application and check if it's downloaded into my local system or not. But when I click the download link I have a popup with Save or Cancel options, which is stopping me from downloading the file. I googled and found some solutions and tried to change the profile of Firefox by adding the below code, but it is not working.

firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.alertOnEXEOpen", false);
firefoxProfile.setPreference("browser.helperApps.neverAsksaveToDisk", "application/x-msexcel,application/excel,application/x-excel,application/excel,application/x-excel,application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel");
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.manager.focusWhenStarting", false);
firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
firefoxProfile.setPreference("browser.download.manager.alertOnEXEOpen", false);
firefoxProfile.setPreference("browser.download.manager.closeWhenDone", false);
firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete", false);
firefoxProfile.setPreference("browser.download.manager.useWindow", false);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);

This is the code I added for setting up Firefox preferences, but I still get the popup.

  • 1
    This sounds like they either custom coded a popup dialog or are forcing the browser acknowledgement of it. Either way you should be able to execute a javascript to accept the dialog in the popup and close it. Do you have the rendered HTML?
    – mutt
    May 9 '17 at 17:05

I think you have missed some crucial options.

Please consider the code taken from this answer. Of course your MIME type will be different.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "C:\\Temp");  // folder
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "video/mp4");  // MIME type
profile.setPreference("pdfjs.disabled", true);  // disable the built-in viewer
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.panel.shown", false);

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, 1);

WebDriver driver = new FirefoxDriver(capabilities);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.