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

Use Selenium’s Python WebDriver method driver.save_screenshot("screenshot.png") to save a PNG of the current browser window. For a single element, call element.screenshot(...); for a document-level capture, Selenium also documents a separate BiDi API. The right choice depends on whether you need the visible browser context, one element, or the whole page.

Capture the current browser window

This is the simplest Selenium-and-Chromium workflow. Selenium documents save_screenshot as saving the current window to a PNG file; in Python, it returns False if the image could not be saved because of an I/O error. See the Python Chromium WebDriver API.

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--headless=new")  # Optional: run without a visible browser window.

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    saved = driver.save_screenshot("screenshot.png")
    if not saved:
        raise OSError("Screenshot could not be saved")
finally:
    driver.quit()

Install Selenium and ensure Chromium/Chrome and its driver are available in your environment. Selenium’s official guide shows the basic webdriver.Chrome() and save_screenshot workflow: Take screenshot. The headless argument is optional; Selenium’s Chrome guide documents passing browser command-line arguments through ChromeOptions and includes --headless=new among commonly used arguments: Chrome-specific WebDriver guidance.

Choose the screenshot scope

Current window or viewport

Use driver.save_screenshot("screenshot.png") when the desired image is the current browser context. The standard call writes PNG output. If you need the image in memory instead of a file, Selenium also provides driver.get_screenshot_as_png() for PNG bytes and driver.get_screenshot_as_base64() for Base64 data. These are useful when another part of your program will store, transmit, or transform the image. The Chromium WebDriver API documents these screenshot methods.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

One element

Locate the element and call its screenshot method to save a crop of that element rather than the whole browser context:

from selenium.webdriver.common.by import By

page_title = driver.find_element(By.CSS_SELECTOR, "h1")
page_title.screenshot("title.png")

This approach is documented in Selenium’s screenshot guide. The selector must match an element on the loaded page; if it does not, locating it raises an error before capture.

Whole document with BiDi

Selenium’s Python BiDi browsing-context API accepts an origin of "document" or "viewport", an optional clip rectangle, and returns Base64 screenshot data. This is a separate API from save_screenshot, not a switch that changes that method’s scope:

encoded = driver.browsing_context.capture_screenshot(
    context=context_id,
    origin="document",  # Use "viewport" for the viewport origin.
)

The API shape is documented in Selenium’s Python BiDi browsing-context reference. BiDi setup and support can depend on the Selenium and browser versions installed, so verify the reference for your version before treating this as a drop-in replacement for the ordinary WebDriver screenshot call.

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

Wait for the page state you actually need

Selenium documents that driver.get(url) waits for the page’s onload event. That event does not guarantee that asynchronous JavaScript, lazy-loaded images, animations, or fonts have reached the visual state you want. For a page that renders content after load, wait for a site-specific condition such as a known element becoming visible or an application state changing.

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

driver.get("https://example.com")
WebDriverWait(driver, 15).until(
    EC.visibility_of_element_located((By.CSS_SELECTOR, "main h1"))
)
driver.save_screenshot("ready.png")

The onload behavior is described in the WebDriver API; using an application-specific wait is an engineering practice for pages whose visible content is not settled at that point. A fixed sleep can waste time on fast pages and still be too short on slow ones.

Keep Chromium and its driver compatible

Selenium’s Chrome guidance says Selenium 4 is compatible with Chrome 75 and greater and advises that Chrome and ChromeDriver have the same major version. This is compatibility guidance from Selenium’s Chrome documentation, not a guarantee for every operating system or installed combination. Check your installed Selenium release’s documentation and match the browser and driver major versions when diagnosing startup problems: Selenium Chrome documentation.

Troubleshooting

  • The browser does not start. Check that Chromium/Chrome is installed and that its driver is available, then compare the browser and driver major versions. Selenium’s Chrome guidance calls for matching major versions.
  • The image is missing or cannot be written. Confirm the destination directory exists and the process can write there. Check the Boolean return from save_screenshot; Selenium documents False for an I/O error.
  • The screenshot is blank or shows a loading state. A successful navigation return means the page’s onload event fired, not that every asynchronous component finished. Wait for the specific element or state your capture requires.
  • The file omits content below the visible area. The ordinary screenshot method captures the current browser context, not a guaranteed whole-document image. For document-origin capture, investigate the separately documented BiDi method and verify support in your installed versions.
  • The element capture fails. Check that the selector matches an element after navigation and after the relevant page state is ready. Element capture requires an element reference, unlike a window screenshot.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a hosted screenshot API rather than maintaining a Selenium/Chromium setup, ScreenshotNeo takes a screenshot or PDF with one GET request. Its clean-shot steps can accept cookie and consent banners and remove known consent platforms, newsletter popups, and chat widgets before capture; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. It also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents using Claude, Cursor, or another MCP client.

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

For the one-call image request, create an API key and replace YOUR_API_KEY. The example saves the returned image as WebP; see the ScreenshotNeo API documentation for parameters and response details.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for ScreenshotNeo to start with the free monthly allowance.

Frequently Asked Questions

What file format does Selenium’s save_screenshot method create?

It saves a PNG file.

Can Selenium return screenshot data without saving a file?

Yes. Its Chromium WebDriver API includes methods that return PNG bytes or Base64 data.

Does save_screenshot capture the full page?

It captures the current browser context. Selenium’s separate BiDi API documents a document origin for whole-document capture, subject to version support.

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.

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.