Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Build the destination path, create its parent directory, then pass the full filename to driver.save_screenshot(). For example, screenshots/page.png saves under a folder named screenshots in the Python process’s current working directory. Check the method’s Boolean return value so a failed write does not go unnoticed.
Save a screenshot to a directory
This complete example opens a page in Chrome, creates a screenshots folder if necessary, saves the current browser window as a PNG, checks whether the write succeeded, and closes the browser even if saving raises an error:
from pathlib import Path
from selenium import webdriver
screenshot_dir = Path("screenshots")
screenshot_dir.mkdir(parents=True, exist_ok=True)
screenshot_path = screenshot_dir / "page.png"
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
saved = driver.save_screenshot(str(screenshot_path))
if not saved:
raise OSError(f"Could not save screenshot to {screenshot_path.resolve()}")
print(f"Screenshot saved to {screenshot_path.resolve()}")
finally:
driver.quit()
Install Selenium in the Python environment that runs the script with python -m pip install selenium. Chrome must also be available. Selenium’s current Python API documentation, which displays version 4.49.0, documents save_screenshot(filename) as saving the current window to PNG and returning a Boolean. The example converts the Path to a string for compatibility with Selenium versions that expect a filename string.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →The important detail is that the directory belongs in the filename. Passing only "page.png" saves in the current working directory; passing "screenshots/page.png" includes a subdirectory. Selenium’s method does not create missing parent directories, so create them before calling it.
#1 Best Overall
Choose a relative or absolute path
A relative path is convenient when screenshots should live inside a project. It is resolved from the Python process’s current working directory—not necessarily from the folder containing the script. That distinction often explains why a file seems to have been saved somewhere unexpected.
| Path type | Example | Best when | Trade-off |
|---|---|---|---|
| Relative | Path("screenshots") / "page.png" |
You want an output folder relative to the process’s working directory. | The final location changes if an IDE, notebook, test runner, or CI job starts Python from a different directory. |
| Absolute | Path("/tmp/project/screenshots/page.png") |
You need to target a known location or are diagnosing a path issue. | The root is machine- or environment-specific unless you configure it. |
To make a relative path’s effective location visible, inspect Path.cwd() and resolve the screenshot path:
print("Working directory:", Path.cwd())
print("Screenshot destination:", screenshot_path.resolve())
On Windows, a raw string avoids treating backslashes as escape sequences: Path(r"C:projectscreenshotspage.png"). You can also compose the path from components, for example Path("C:/project") / "screenshots" / "page.png". Substitute a directory that exists and is writable in your own environment.
Recommended Free Tools
Rank #2
Create the folder before saving
Use mkdir(parents=True, exist_ok=True) on the directory, not on the image filename:
screenshot_dir = Path("screenshots")
screenshot_dir.mkdir(parents=True, exist_ok=True)
screenshot_path = screenshot_dir / "page.png"
parents=True creates missing directories higher in the path as well. exist_ok=True allows the folder to be present already, which makes the setup safe to run repeatedly. These arguments are documented in Python 3.14.7’s pathlib documentation. For older Python code or a project already using os.path, os.makedirs(path, exist_ok=True) is an alternative; check the documentation for the Python runtime you support.
Understand the result and file format
save_screenshot() captures the current browser window and writes PNG data. A successful write returns True; an I/O error returns False. Always check that result if the screenshot is important to a test, report, or pipeline. A .png filename suffix is the appropriate choice: changing the suffix to .jpg does not make Selenium encode a JPEG.
Rank #3
This method is for the current window capture; do not assume it produces a full-page image of a long document. If the requirement is specifically a full-page capture, confirm that the browser, driver, and capture approach you use supports it rather than treating a longer filename or a different extension as a setting for full-page output.
Free tools Windows power users keep installed
One-click scans. No signup required.
Diagnose a screenshot that is missing or misplaced
The file appears in the wrong folder
Print Path.cwd() and screenshot_path.resolve() in the same process that calls Selenium. Relative paths begin at the process working directory, which can differ between running a script from a terminal, launching it from an IDE, executing a notebook, or starting a CI job.
The method returns False
Check that the parent directory exists, that the Python process has permission to write there, and that the destination is not blocked by another filesystem problem. Selenium’s implementation catches an OSError while writing and returns False; raise or log an error in your own code rather than silently continuing.
Rank #4
The method returns True, but you cannot see the file
First verify the resolved destination, then check that you are inspecting the same machine and filesystem used by the Python process. This matters with containers, CI workers, and remote WebDriver: the Selenium Python method receives screenshot bytes and writes the supplied filename through Python’s file handling on the Python side. A browser running elsewhere does not, by itself, mean the file was written to that browser machine’s local folder.
A path object causes compatibility trouble
Pass str(screenshot_path) as in the example. Modern Python path objects implement the os.PathLike interface, and current Selenium Python code converts the filename to a string internally, but an explicit conversion is clear and works with older versions that may handle path-like arguments differently.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallThe image has the wrong format or will not open as expected
Use a filename ending in .png and treat the result as PNG. Selenium’s API documents PNG output; the implementation can warn when the suffix is not .png, but a different suffix does not convert the image’s encoding.
Keep screenshot output reliable in scripts and tests
- Create the directory before capture. Do this once during setup or immediately before saving, so the write does not depend on a folder having been created manually.
- Make the destination observable. Log the resolved path when debugging, or configure an absolute output directory when the deployment environment has a known location.
- Fail visibly on an unsuccessful write. A
Falseresult is not a saved file. Raise an exception or otherwise make the failure visible to the calling test or job. - Use distinct names for repeated captures. A fixed filename is overwritten by a later capture at the same destination. If each run must be retained, compose a unique filename in your own application logic.
- Close the driver even after errors. A
finallyblock, as in the example, ensures the browser session is closed if navigation or screenshot handling fails.
Saving the returned PNG involves writing the image bytes to the destination; the key operational constraints are path resolution, directory existence, and filesystem permissions. The official API and implementation describe the write behavior, but they do not establish a universal capture-time benchmark or guarantee for a particular machine, browser, or remote execution setup.
Or skip the browser setup
If you need a screenshot from a URL without configuring Selenium and a browser, ScreenshotNeo is a website screenshot API and MCP server for developers. Its Python call is:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
See the ScreenshotNeo API documentation for setup and request options. Cookie banners are accepted as a visitor and removed along with known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers indicate the page verdict and billing status. Its MCP server gives AI agents screenshot, page-info, and PDF-capture tools. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up free and try ScreenshotNeo.
Frequently Asked Questions
Does save_screenshot() capture the whole page?
It is documented as saving the current browser window. A full-page capture is a separate requirement; verify that your chosen browser and capture method supports it.
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.

