0

I am using Selenium and Firefox for automated testing, and I need the files to download automatically. Here are two links that I've used to setup my code.

Auto download PDF in Firefox

Set Firefox profile to download files automatically using Selenium and Java

To summarize the articles, the code should look like this:

FirefoxOptions options = new FirefoxOptions();
options.setPreference("browser.download.folderList", 2);
options.setPreference("browser.download.dir", "C:\\Windows\\temp");
options.setPreference("browser.download.useDownloadDir", true);
options.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
options.setPreference("pdfjs.disabled", true);  // disable the built-in PDF viewer

WebDriver driver = new FirefoxDriver(options);

When I run my test, the auto-download fails. I checked in the about:config and the settings have been changed as intended by the code. (about:config screenshot)

Also, within that driver instance, if I change any setting and then reapply the same setting, the auto-download works. Is there a setting or step with the webdriver that I'm missing that then applies the new settings?

Here are the Selenium, Firefox, and GeckoDriver versions I've tested with:

Selenium: v3.12.0

Firefox: 59.0.3, 60.0.1

GeckoDriver: v0.19.0-win64, v0.20.0-win64, v0.21.0-win64

1 Answers1

0

As far as i know is pretty difficult download files with selenium because the browser open some dialogs that is not possible control from javascript. Watch this link, I hope will be useful

andrexorg
  • 77
  • 4