4

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
  • 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, 2017 at 17:05

2 Answers 2

1

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);
0
0

I've showed here how you can avoid any warning/pop-up while downloading any potentially harmful files like .exe, .jar etc in Chrome & Firefox (v113) using Selenium 4.9.1. Do the following:

HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("safebrowsing.enabled","true");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
2
  • Please describe the steps needed in your answer and leave the video as a reference. Not everyone has easy access to YouTube.
    – Kate Paulk
    Jun 9 at 19:00
  • @KatePaulk - Thank you remind me that. I've edited my answer with the steps to solve the problem. It's recommended to go through the video to get better explanation and view in action. Hope it helps. Jun 10 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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