October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Download Files with Selenium and Python

For file-content checks, let Selenium find the download and Python fetch it. For browser-download tests, configure the browser folder and verify completion; for Grid, enable managed downloads and retrieve the file to the client.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For reliable file-content tests, use Selenium to reach the page and identify the download URL, then fetch the file with Python’s HTTP client. If you need to test the browser’s download interaction, configure a browser-specific download folder and verify the file separately: a Selenium click starts a download but does not report when it finishes.

Choose the right download method

Method Best for Where the file ends up Main limitation
HTTP request after Selenium navigation Checking file retrieval, bytes, or contents A path chosen by your Python test Authentication, cookies, redirects, and streaming vary by application.
Browser download to a configured folder Testing the browser’s download interaction The machine running the browser WebDriver does not expose download progress.
Grid managed download Retrieving a file from a remote browser session Downloaded from the remote session to the client Requires server and session configuration; listed files are only a snapshot.

Selenium’s guidance recommends using WebDriver to locate a link and obtain any necessary cookies, then using an HTTP library to retrieve the file when the test is about the downloaded file itself. Selenium’s file-download guidance explains why: WebDriver does not expose download progress, so a click alone is not proof that the complete file has arrived.

Download a file through Python after Selenium finds it

This pattern keeps browser automation for the page state and link discovery, while Python handles the file transfer. The example uses Requests and assumes the link is a normal HTTP(S) resource and that the site’s session cookies are sufficient. Authentication headers, redirects, signed URLs, and streaming endpoints may require application-specific handling.

  1. Navigate with Selenium and locate the actual download link.
  2. Read its resolved URL and transfer the session cookies the site requires.
  3. Request the URL and check the HTTP status before saving.
  4. Validate the resulting file using an application-appropriate check, such as expected content or file signature.
from pathlib import Path
from urllib.parse import urljoin

import requests
from selenium import webdriver
from selenium.webdriver.common.by import By

output = Path("downloads")
output.mkdir(parents=True, exist_ok=True)

 driver = webdriver.Chrome()
try:
    driver.get("https://example.com/reports")
    link = driver.find_element(By.CSS_SELECTOR, "a.download")
    download_url = urljoin(driver.current_url, link.get_attribute("href"))

    session = requests.Session()
    for cookie in driver.get_cookies():
        session.cookies.set(
            cookie["name"], cookie["value"],
            domain=cookie.get("domain"), path=cookie.get("path", "/")
        )

    response = session.get(download_url, stream=True, timeout=(10, 90))
    response.raise_for_status()
    destination = output / "report.csv"
    with destination.open("wb") as file:
        for chunk in response.iter_content(chunk_size=64 * 1024):
            if chunk:
                file.write(chunk)
    assert destination.stat().st_size > 0
finally:
    driver.quit()

Replace the example URL, selector, and output filename with values from your application. The cookie transfer shown is a starting point, not a universal authentication bridge: cookies with unusual scope, CSRF tokens, authorization headers, or browser-managed download flows may need additional handling. For large files, streaming avoids loading the whole response into memory. If the site returns a redirect, Requests follows ordinary redirects by default, but verify the final response and saved content rather than relying only on a successful request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure a browser download folder for local tests

Chrome, Edge, and Firefox have browser-specific ways to configure downloads. Selenium does not provide one universal preference dictionary that works across all three. Build the selected browser’s options before creating the driver, and consult the options reference for the browser and Selenium version in use. The current Python references document enable_downloads on ChromeOptions and Firefox Options, alongside Firefox-specific preference methods. ChromeOptions API and Firefox Options API describe the binding-specific interfaces.

from pathlib import Path
from selenium import webdriver

folder = Path("downloads").resolve()
folder.mkdir(parents=True, exist_ok=True)

# Set the selected browser's own download-directory options/preferences here.
# Then create the driver with those options and navigate or click as needed.

This intentionally leaves the preference assignment browser-specific rather than suggesting that a Chrome setting is a Selenium-wide API. With a local session, the directory is on the machine running the browser. A click only initiates the action; it does not tell the test that the browser has finished writing the file.

Wait for completion without trusting a click or fixed sleep

Prefer an application-level completion signal where you can change the application under test. Otherwise, poll for the expected file and ensure any browser-specific temporary or partial-download file has disappeared before opening it. A file’s appearance may precede the end of the transfer, so check a suitable completion condition and then validate the contents. Avoid a hard-coded sleep: it can be too short on a slow run and needlessly long on a fast one.

Retrieve downloads from Selenium Grid

In Remote WebDriver, the browser’s filesystem is on the remote machine, not the Python client. Grid managed downloads let the client list and retrieve files for a session. The feature is documented for Chrome, Firefox, and Edge. Remote WebDriver documentation covers the remote-session context.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Start the Grid node or standalone server with managed downloads enabled, for example --enable-managed-downloads true.
  2. Request managed downloads for the session with the se:downloadsEnabled capability. Current Python browser options expose enable_downloads; confirm that your binding serializes the capability as required by your Grid version.
  3. Trigger the browser download and wait until it is complete. The downloadable-file list is an immediate snapshot, not a wait operation.
  4. List and retrieve the file to a client-side directory.

For example, after the application or test has established that the download is complete:

from pathlib import Path

folder = Path("downloads").resolve()
folder.mkdir(parents=True, exist_ok=True)

files = driver.get_downloadable_files()
assert "report.csv" in files

driver.download_file("report.csv", str(folder))

The Python remote API also exposes delete_downloadable_files() if you need to remove managed files during the session. Grid-managed files are session-scoped and are cleaned up when the session ends or times out. See Grid CLI options for server configuration and Python Remote WebDriver API for the client methods.

Troubleshoot common failures

  • The click succeeds, but the file is missing or incomplete: a click is not a completion signal. Wait for an application signal or poll for a stable, complete file before reading it.
  • The HTTP request returns an error or an HTML login page: the request may lack required cookies, headers, or a valid signed URL. Inspect the response status, final URL, and content type; transfer only the authentication state the application requires.
  • The browser saves somewhere unexpected: verify that the configured preference belongs to the selected browser, that the folder exists, and that the path is valid on the machine running that browser.
  • The Grid client reports no downloadable files: confirm the server was started with managed downloads enabled and that the session requested se:downloadsEnabled. The file list is a snapshot; query again after completion.
  • The file is unavailable after the session ends: managed downloads follow the session lifecycle. Retrieve the file before ending the session, or use a deployment-appropriate shared storage arrangement.
  • Browser startup or driver compatibility fails: check the browser, driver, Selenium binding, and Grid versions together. Selenium’s Chrome guidance says Selenium 4 is compatible with Chrome 75 and later and that Chrome and ChromeDriver major versions must match; its Firefox guidance says Selenium 4 requires Firefox 78 or later and recommends the latest geckodriver. These are documented compatibility statements, not a guarantee for every hosted combination. See Chrome guidance and Firefox guidance.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Version context

Selenium’s downloads page listed Python binding version 4.49.0, released September 9, 2026. Check the Selenium downloads page and the APIs for the versions actually installed in your environment; browser options and Grid support can differ by binding and server version.

Or skip the browser setup

If your goal is a clean image or PDF of a web page rather than testing a file-download workflow, ScreenshotNeo offers a one-request screenshot API. For other download scenarios, Selenium remains appropriate when you need to exercise the browser or a page’s authenticated file flow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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 request options. It accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server provides screenshot, page-info, and PDF tools for AI agents. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for 1,000 free screenshots a month, no card required.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.