We're calling on all EU-based Mozillians with iOS or iPadOS devices to help us monitor Apple’s new browser choice screens. Join the effort to hold Big Tech to account!

Ce site disposera de fonctionnalités limitées pendant que nous effectuons des opérations de maintenance en vue de vous proposer un meilleur service. Si un article ne règle pas votre problème et que vous souhaitez poser une question, notre communauté d’assistance est prête à vous répondre via @FirefoxSupport sur Twitter, et /r/firefox sur Reddit.

Rechercher dans l’assistance

Évitez les escroqueries à l’assistance. Nous ne vous demanderons jamais d’appeler ou d’envoyer un SMS à un numéro de téléphone ou de partager des informations personnelles. Veuillez signaler toute activité suspecte en utilisant l’option « Signaler un abus ».

En savoir plus

Need the correct Firefox profile settings for Java to make web app automatically download a file

  • 4 réponses
  • 2 ont ce problème
  • 1 vue
  • Dernière réponse par the-edmeister

more options

I am writing selenium webdriver/java code to automate testing a website. I want to test file downloads from the site so that when the download button is clicked, firefox automatically saves the file to the specified location without prompting via a pop up window.

Furthermore, I would like the ability to download the following file types:

pdf pages doc odt docx

I am using these settings but it is not working:

firefoxProfile.setPreference("browser.download.folderList", 2); firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false); firefoxProfile.setPreference("browser.download.dir", "C:\\Users\\Amillikin\\Downloads"); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");

driver = new FirefoxDriver(firefoxProfile);

However, the system pop up asking me to save the file still appears.

I am writing selenium webdriver/java code to automate testing a website. I want to test file downloads from the site so that when the download button is clicked, firefox automatically saves the file to the specified location without prompting via a pop up window. Furthermore, I would like the ability to download the following file types: pdf pages doc odt docx I am using these settings but it is not working: firefoxProfile.setPreference("browser.download.folderList", 2); firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false); firefoxProfile.setPreference("browser.download.dir", "C:\\Users\\Amillikin\\Downloads"); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf"); driver = new FirefoxDriver(firefoxProfile); However, the system pop up asking me to save the file still appears.

Toutes les réponses (4)

more options

Automatic Save Folder {web link} This add-on will open the File Browser at the right location, using simple filters on the downloaded file. The filters are based on filenames and hosted domain's name. WARNING ! May not work with other downloader programs.

more options

Thank you for your response however I think you might have misunderstood my question.

I am not interested in using a Firefox add-on. Instead, I am interested in programmatically creating a Firefox profile using Java. Then when Selenium starts the Firefox browser, it uses this profile. I want to know how to create this Firefox profile so that when my web app downloads a file, the pop up window automatically defaults to the SAVE option rather than the OPEN option.

Does this make sense?

I have seen a few responses on Stackoverflow on how to set the preferences to achieve this. However, I cannot seem to get it to work.

Could you please tell me where I can find Firefox documentation on the preferences to make this work? I included what I am using in my original posting.

Thank you.

more options

More comments:

Firefox ignores my preference: firefoxProfile.setPreference("browser.download.dir", "C:/Users/Amillikin/Downloads");

Instead it downloads to: C:\Users\Amillikin\AppData\Local

This is with Windows 7 and FF Version 41.0.2.

Also, I cannot get the firefox profile to trigger the save option when the script downloads a Word Doc (.doc), but I can with with a PDF. This is the case with these options (added the plugin.disable preference). firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false); firefoxProfile.setPreference("browser.download.dir", "C:/Users/Amillikin/Downloads"); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf,application/msword"); firefoxProfile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf,application/msword");

more options

This forum is for end user Firefox support. Perhaps a selenium developer related support website would be able to help you or a developer site or mailing list. https://support.mozilla.org/en-US/kb/where-go-developer-support