Prohledat stránky podpory

Vyhněte se podvodům. Za účelem poskytnutí podpory vás nikdy nežádáme, abyste zavolali nebo poslali SMS na nějaké telefonní číslo nebo abyste sdělili své osobní údaje. Jakékoliv podezřelé chování nám prosím nahlaste pomocí odkazu „Nahlásit zneužití“.

Zjistit více

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

  • 4 odpovědi
  • 2 mají tento problém
  • 1 zobrazení
  • Poslední odpověď od 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.

Všechny odpovědi (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