Set the download directory in the browser’s Options object before you create the WebDriver session. Chrome uses the download.default_directory preference; Firefox uses profile preferences supplied through Firefox Options. The directory is local to the machine running the browser, so a remote session saves on the remote host unless Selenium Grid managed downloads are enabled.
What you configure, and when
Selenium 4 uses browser-specific Options classes to configure a session. Build the options, add the download preferences, and pass those options to ChromeDriver, FirefoxDriver, or RemoteWebDriver. Changing a preference after the session starts is too late for reliable download behavior.
- Choose an absolute, writable directory.
- Create a separate directory per test when possible, so old files cannot be mistaken for new downloads.
- Start the driver only after all browser preferences are set.
- Wait for your own completion condition before quitting or opening the file; browser startup does not mean a download is finished.
Chrome: set download.default_directory
Java with ChromeOptions
ChromeDriver accepts a preference map through setExperimentalOption("prefs", ...). Use a full path and verify that the test process can write to it.
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class ChromeDownload {
public static void main(String[] args) throws Exception {
Path downloadDir = Files.createTempDirectory("selenium-download-");
Map<String, Object> prefs = new HashMap<>();
prefs.put("download.default_directory", downloadDir.toAbsolutePath().toString());
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
try {
driver.get("https://example.com/report");
driver.findElement(By.cssSelector("a.download")).click();
// Wait here until the expected file exists and is complete.
} finally {
driver.quit();
}
}
}
On Windows, provide a valid Windows path with backslashes (for example, C:\tests\downloads) or use Java’s Path API as in the example. ChromeDriver’s guidance warns against special system directories: the desktop directory is disallowed, Linux home is disallowed, and the exact restricted set can change. Do not assume that a path accepted on one operating system is valid on another.
#1 Best Overall
- USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
- Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
- Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
- Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
- Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty
Chrome in Python
from pathlib import Path
import tempfile
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
path = Path(tempfile.mkdtemp(prefix="selenium-download-"))
options = Options()
options.add_experimental_option(
"prefs",
{"download.default_directory": str(path.resolve())}
)
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com/report")
driver.find_element("css selector", "a.download").click()
# Poll path until the expected file exists and any temporary download is gone.
finally:
driver.quit()
Firefox: configure the profile before startup
Firefox writes preferences supplied through FirefoxOptions (or a profile attached to those options) into the profile before Firefox starts. The exact preference names and values needed to handle a particular MIME type can vary by Firefox version and language binding, so verify them against the version you run rather than copying a supposedly universal recipe.
JavaScript with Firefox Options
const { Builder } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
const options = new firefox.Options()
// Replace these with the preferences appropriate for your Firefox version
// and the MIME types your test downloads.
.setPreference('browser.download.folderList', 2)
.setPreference('browser.download.dir', '/absolute/path/to/downloads');
(async () => {
const driver = await new Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
try {
await driver.get('https://example.com/report');
// Click the download control and wait for a completed file.
} finally {
await driver.quit();
}
})();
The setPreference(name, value) API is the important part. Add MIME-handling preferences only after checking the target Firefox release and the file types involved; a setting that works for one content type or release may not produce the same result elsewhere.
Python with FirefoxProfile
from pathlib import Path
import tempfile
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
download_dir = Path(tempfile.mkdtemp(prefix="selenium-firefox-download-")).resolve()
profile = FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.dir", str(download_dir))
# Add version-appropriate MIME preferences when required by your application.
profile.update_preferences()
options = Options()
options.profile = profile
driver = webdriver.Firefox(options=options)
try:
driver.get("https://example.com/report")
finally:
driver.quit()
A Firefox profile can be created fresh or cloned from an existing profile. Supplying preferences through the profile or through the moz:firefoxOptions preferences object has the same timing requirement: apply them before the browser process launches.
Rank #2
- High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
- Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
- Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
- Sleek, durable metal casing
- Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]
Waiting for a download to finish
Neither browser startup nor a click proves that the file is ready. ChromeDriver does not wait for downloads to finish, and quitting immediately can terminate an active transfer. Use an explicit wait that matches your application.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
- Wait until the expected filename exists.
- Ignore temporary download names while the browser is writing.
- Require the file size (or modification time) to remain unchanged for a short polling interval when partial files are possible.
- Check that the file can be opened or parsed before the test proceeds.
- Apply a test timeout and report the directory contents when it expires.
Do not rely only on “the directory is non-empty”: a previous artifact, an error page saved as a file, or a still-growing temporary file can make that check pass incorrectly.
Remote WebDriver: where the file really goes
With Remote WebDriver, the browser’s configured directory is on the remote computer, not automatically on the machine running your test code. This distinction explains many “missing download” failures: the browser saved successfully, but the test looked in a local directory that the browser never used.
Rank #3
- What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
- Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
- Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
- Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
- Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers
Use Selenium Grid managed downloads
- Start the Grid node or standalone server with
--enable-managed-downloads true. - Enable the client capability
se:downloadsEnabledthrough your binding’s browser Options class. - Start the remote session with those options.
- Use Selenium’s downloadable-file endpoints to list and retrieve files from the session.
A file listing is an immediate snapshot; it is not a wait for completion. Keep the browser-side completion wait (or poll until the expected file appears) before requesting the managed download.
Remote Java pattern
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
prefs.put("download.default_directory", "/tmp/test-downloads");
options.setExperimentalOption("prefs", prefs);
options.setCapability("se:downloadsEnabled", true);
WebDriver driver = new RemoteWebDriver(
new java.net.URL("http://grid-host:4444"), options);
The path above exists on the Grid host. If managed downloads are not enabled, retrieve the file using your infrastructure’s method (for example, a shared volume or an artifact transfer) rather than expecting it in the client process’s filesystem.
Free tools Windows power users keep installed
One-click scans. No signup required.
Chrome and Firefox compared
| Concern | Chrome | Firefox |
|---|---|---|
| Configuration surface | ChromeOptions preference map via download.default_directory |
Firefox profile preferences via FirefoxOptions or FirefoxProfile |
| Path guidance | Use a full path; avoid restricted system directories; Windows separators matter | Verify path and preference behavior for the target Firefox version and operating system |
| Completion | ChromeDriver does not wait automatically | Implement an explicit file-completion wait as well |
| Remote execution | The directory is on the remote host unless Grid managed downloads transfer the file | |
Troubleshooting
The file is not in the directory
- Print the resolved absolute path and confirm it is writable by the browser process.
- Confirm the preference was added before constructing the driver.
- Check that the click really initiated a download and did not open a new tab, authentication page, or inline viewer.
- For Remote WebDriver, inspect the remote host rather than the client host.
The test ends with a partial file
Extend the wait and detect temporary names or changing file size. Move driver.quit() into the cleanup block only after the completion condition succeeds or times out with diagnostics.
Rank #4
- GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
- BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
- EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
- TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
- WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.
Chrome rejects the path
Replace relative paths and special directories with a newly created absolute directory. On Windows, construct the path with the operating system’s path API to avoid malformed separators.
Firefox opens a save dialog
Inspect the response MIME type and configure the corresponding Firefox profile preferences for your exact Firefox release. There is no single preference list that is guaranteed for every file type, version, and binding.
Remote file listing is empty
Ensure the server was started with managed downloads enabled, the session has se:downloadsEnabled, and the download has completed. Listing before completion returns only the files visible at that instant.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchBest Value
- 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
- 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
- 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
- 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
- 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.
Performance, isolation, and reliability practices
- Use a per-test temporary directory and delete it after collecting failure artifacts.
- Reuse a driver only when tests can safely share browser state; otherwise, a fresh session prevents stale files and preferences.
- Keep download timeouts separate from page-load timeouts so a slow transfer produces a useful error.
- Record the browser version, operating system, resolved path, and directory listing in test logs.
- For parallel tests, never point multiple sessions at the same directory unless filename collisions are impossible.
- On remote infrastructure, provision disk space and a cleanup policy on the browser host or Grid-managed storage.
Or skip the browser setup
If your goal is an image or PDF of a web page rather than testing a browser download, ScreenshotNeo returns a capture with one request. Its API can remove cookie-consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. It also offers an MCP server so Claude, Cursor, and other MCP clients can call take_screenshot, get_page_info, and capture_pdf.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for all options, including PNG, JPEG, WebP, PDF, full-page capture, selectors, custom CSS and JavaScript, device emulation, signed links, asynchronous jobs, and bulk capture. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
FAQ
Can I change the directory after creating the driver?
Do it by starting a new browser session with revised Options. Preferences are intended to be applied before startup.
Does Selenium copy remote downloads to my computer automatically?
No. The browser writes to the remote host. Grid managed downloads are the Selenium-supported transfer mechanism when enabled.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesIs a non-empty download directory enough to pass a test?
No. Validate the expected filename and completion state; unrelated or partial files can make a non-empty check pass falsely.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

