skip to content

In Selenium, which Firefox preferences must be set together for a download to reach a folder you chose?

level: middleimportance: nice to knowfreq 31%

answer

  1. A path on its own is ignored
  2. Firefox needs a mode plus a folder
  3. One integer decides which folder wins
  4. The no-dialog list holds MIME types
  5. Mode value two means the custom directory

basics

~10 s

Firefox needs browser.download.folderList set to 2 so that browser.download.dir is honoured, plus browser.helperApps.neverAsk.saveToDisk listing the MIME types to save without asking. All of them go on FirefoxOptions with addPreference.

solid answer

~40 s

A path alone is not enough in Firefox. `browser.download.dir` is only consulted when `browser.download.folderList` is `2`; the values `0` and `1` mean the desktop and the system Downloads folder, and Firefox will quietly use those instead. You then need `browser.helperApps.neverAsk.saveToDisk` set to a comma-separated list of **MIME types** — `text/csv` for a shipments export, `application/pdf` for a bill of lading — so the unknown-content-type dialog never opens, and `browser.download.useDownloadDir` left at `true` so it does not ask each time. All of them go on `FirefoxOptions` via `addPreference`. For a PDF, add `pdfjs.disabled` set to `true`, otherwise Firefox renders it in its own viewer instead of saving it.

go deeper

for a junior

Know that Firefox is configured through named preferences on the options object, and that a download folder is chosen before the browser starts rather than at the moment of the click.

for a middle

Be ready to explain why the path preference is inert on its own, what each folderList value selects, and that the never-ask list matches the content type the server sent.

for a senior

Demonstrate diagnosing a download that vanished into the default Downloads folder, and knowing that these preferences configure the browser's host, not the machine running the suite.

for a principal

Weigh whether a cross-browser suite should carry two divergent preference sets for downloads at all, or standardise its file assertions on one browser and cover the rest elsewhere.

## Why a path alone is not enough Chrome takes one directory preference and behaves. Firefox splits the same decision across a **mode** and a **path**, and a test that sets only the path silently gets the user's ordinary Downloads folder — the file exists, just not where the assertion is looking. On a **freight-tracking dashboard** exporting a shipments CSV, that failure reads as "the download never happened", which sends people hunting in the wrong place entirely. Selenium's job here is only to seed the preferences: `FirefoxOptions.addPreference(name, value)` writes them into the profile the driver creates for the session, exactly as `prefs` does for Chrome. The semantics of each key belong to Firefox. - The preferences are applied when the session profile is built, so they cannot be changed mid-test. - `addPreference` is overloaded for string, boolean and integer values; `folderList` is an integer, not a quoted number. - The profile is temporary and discarded at `quit()`, so nothing persists into a real Firefox profile. ## The preference set | Preference | Value | What it controls | |---|---|---| | `browser.download.folderList` | integer `0`, `1` or `2` | Which folder finished downloads go to | | `browser.download.dir` | absolute path string | The custom folder, consulted only when `folderList` is `2` | | `browser.download.useDownloadDir` | boolean | `true` uses the configured folder instead of asking every time | | `browser.helperApps.neverAsk.saveToDisk` | comma-separated MIME types | Types saved straight to disk with no dialog | | `pdfjs.disabled` | boolean | `true` turns off the built-in PDF viewer so PDFs are saved | ## What folderList's three values mean 1. `0` — the desktop. 2. `1` — the browser's own default Downloads folder. 3. `2` — the folder named by `browser.download.dir`. Only the third makes your path relevant, and the default is not `2`. This single integer is the most common reason a carefully written Firefox download test looks for its manifest in a directory that stays empty for the whole run. ```java FirefoxOptions options = new FirefoxOptions(); options.addPreference("browser.download.folderList", 2); options.addPreference("browser.download.dir", exports.toAbsolutePath().toString()); options.addPreference("browser.download.useDownloadDir", true); options.addPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/pdf"); options.addPreference("pdfjs.disabled", true); WebDriver driver = new FirefoxDriver(options); ``` ## MIME types, not file extensions `browser.helperApps.neverAsk.saveToDisk` is the preference people get wrong twice over. It takes **content types**, so `text/csv` and `application/pdf`, never `.csv` or `.pdf`. And the type it matches is the one the **server** sent in the response, not the one the filename suggests. A dashboard that serves its export as `application/octet-stream` needs that string in the list, however clearly the file is named `shipments.csv`. - Several types are separated by commas with no spaces. - A type absent from the list makes Firefox open its unknown-content-type dialog, which is browser UI your test cannot reliably drive. - Content Firefox can render itself — a PDF above all — never reaches that dialog at all, which is what `pdfjs.disabled` is for. ## Chrome and Firefox side by side | Concern | Chrome | Firefox | |---|---|---| | Destination folder | `download.default_directory` | `browser.download.dir` plus `browser.download.folderList` at `2` | | Suppressing the prompt | `download.prompt_for_download` at `false` | `browser.download.useDownloadDir` at `true` | | Per-type dialog | not applicable | `browser.helperApps.neverAsk.saveToDisk` by MIME type | | Forcing PDFs to disk | `plugins.always_open_pdf_externally` at `true` | `pdfjs.disabled` at `true` | | How Selenium passes them | `prefs` map on `ChromeOptions` | `addPreference` on `FirefoxOptions` | Edge is Chromium-based and takes the Chrome names through `EdgeOptions`. Safari exposes no equivalent preference surface through its driver, which is why download assertions are usually left to the other browsers. ## What these preferences still do not give you They choose a destination and remove dialogs. They do not tell you the transfer finished, and they do not move anything between machines. - Firefox writes an in-progress download as a `.part` file beside the target and renames it when the transfer completes, so poll for the final name rather than the first file that appears. - The path is resolved by the browser process; against a remote node it is a directory on that node, and Selenium 4's Grid managed downloads, requested with the `se:downloadsEnabled` capability, are the way to bring the file back to the client. - Nothing here changes what the server sends; the dialog Firefox shows for an unexpected type is suppressed by the MIME list, not by the folder settings.

  • The export is served as application/octet-stream but named shipments.csv. Which value goes in the never-ask list?
    `application/octet-stream`, because Firefox matches on the content type the server sent, not on the filename. Listing `text/csv` alone leaves the unknown-content-type dialog open. Adding both types is the pragmatic fix when the header may vary by environment.
  • Why does a PDF still open in a tab even with the never-ask list configured?
    Firefox can render PDFs itself, so the response never reaches the unknown-content-type path that list guards. Setting `pdfjs.disabled` to `true` turns the built-in viewer off, after which the PDF is treated as a download and the folder preferences apply.

saying these in an interview costs you the question

  • Sets browser.download.dir without setting folderList to 2
  • Puts file extensions in the never-ask list instead of MIME types
  • Passes the folderList value as a string rather than an integer
  • Expects the never-ask list to stop Firefox rendering a PDF
  • Assumes Chrome's preference names work on Firefox