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.

In Python, call driver.save_screenshot("screenshot.png") after navigating to the page. For a screenshot of just one element, locate it and call element.screenshot("element.png"). Selenium has equivalent methods in other language bindings, but the exact output handling differs by language. The basic driver call captures the current browsing context; do not assume it captures an entire long page in every browser and driver setup.

Capture a browser screenshot in Python

The most direct Selenium workflow is to start a WebDriver, open a URL, save the current browsing context to an image path, and close the browser. Selenium’s official Python API documentation, versioned Selenium 4.49.0, demonstrates this pattern.

from selenium import webdriver

# Assumes Chrome and a working WebDriver setup are available.
driver = webdriver.Chrome()
try:
    driver.get("https://www.example.com")
    driver.save_screenshot("screenshot.png")
finally:
    driver.quit()

Run the script from the directory where you want the PNG to appear, or replace the filename with an absolute path. The file extension should match the image format you want to save. The example uses Chrome; the Selenium method is part of the language binding, while browser and driver behavior can vary.

The finally block closes the browser even if navigation or screenshot capture raises an error. Without a reliable shutdown path, a failed script can leave browser processes running. If you need to inspect the page after a failure, temporarily remove or defer the quit() call while debugging, then restore it for normal runs.

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

Capture only one element

Use an element screenshot when you need a chart, heading, product card, or other specific region rather than the whole current browsing context. Locate the element after navigating, then call its screenshot() method with the output path.

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

# Assumes Chrome and a working WebDriver setup are available.
driver = webdriver.Chrome()
try:
    driver.get("https://www.example.com")
    heading = driver.find_element(By.CSS_SELECTOR, "h1")
    heading.screenshot("heading.png")
finally:
    driver.quit()

This captures the located element, not an arbitrary CSS selector string: first find the element, then invoke the method on that element. If the selector matches nothing, Selenium cannot take the element screenshot; verify the page loaded and that the selector identifies an element on the current page.

What the screenshot includes—and what it may not

Current browsing context

The driver-level operation is documented as capturing the screenshot for the current browsing context. Use it for the browser view Selenium has opened, rather than treating it as a guarantee of a complete document image of unlimited height.

Element capture

The element-level operation is intended for a specific element. It is useful when the deliverable should exclude surrounding page content, but it does not turn a full-page capture into a reliable cross-browser feature.

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

Full-page capture

The cited Selenium documentation establishes current-context and element screenshots; it does not settle the behavior of full-page screenshots across browser, driver, and Selenium configurations. If you need the entire document rather than the current view, verify the exact browser, driver, Selenium version, and supported capture method in your own target environment. Do not infer full-page support from the existence of save_screenshot().

Use the binding that matches your language

Selenium provides screenshot capability through its language bindings, but the method name and output-handling step are language-specific. The WebDriver screenshot endpoint returns Base64-encoded image data; a binding may save it to a path or expose it for you to write.

Language Documented approach Output handling
Python driver.save_screenshot('./image.png'); for one element, element.screenshot('./image.png') Pass a path to the binding method.
Java Use TakesScreenshot and getScreenshotAs(OutputType.FILE). Save or copy the resulting file.
JavaScript Call driver.takeScreenshot(). The documented example receives Base64-encoded image data and writes it as Base64.
C# Call ITakesScreenshot.GetScreenshot(). Save the returned Screenshot with SaveAsFile(...).
Ruby and Kotlin The Selenium examples show saving a screenshot to a path or file. Follow the output handling used by the relevant binding example.

JavaScript example

This example shows the Base64 output path described in Selenium’s documentation. It uses Chrome’s headless option as a documented example, not because ordinary screenshots universally require headless mode.

const { Builder } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const fs = require('node:fs');

(async function capture() {
  const options = new chrome.Options().addArguments('--headless');
  const driver = await new Builder()
    .forBrowser('chrome')
    .setChromeOptions(options)
    .build();

  try {
    await driver.get('https://www.example.com');
    const image = await driver.takeScreenshot();
    fs.writeFileSync('screenshot.png', image, 'base64');
  } finally {
    await driver.quit();
  }
})();

The JavaScript example requires the Selenium JavaScript binding and a Chrome setup that can start through WebDriver. If your project uses a different binding or browser, use that binding’s documented setup and screenshot output convention rather than copying the Chrome-specific initialization unchanged.

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

Java and C# method shape

The official binding examples use TakesScreenshot, getScreenshotAs(OutputType.FILE), and file saving or copying in Java. In C#, obtain a Screenshot with ITakesScreenshot.GetScreenshot() and call SaveAsFile(...). The exact imports, driver construction, and file-copy APIs depend on the project and binding version, so use the corresponding Selenium binding example for a complete program in that environment.

Headless mode: optional for screenshots

Selenium’s official JavaScript example configures Chrome with --headless and then takes a screenshot. That demonstrates that a headless browser can be used for the example; it does not establish that headless operation is required for ordinary screenshot capture.

Keep this separate from PDF generation. Selenium’s documentation states that its page-to-PDF capability requires Chromium browsers to be in headless mode. That PDF-specific requirement should not be applied to regular image screenshots.

Common failures and how to narrow them down

  • No image file appears: Check the working directory and whether the path is writable. Use an absolute output path to remove ambiguity, and make sure the script reaches the screenshot call before exiting.
  • The browser does not start: The examples assume a working browser and WebDriver setup. Resolve browser/driver startup or configuration issues before diagnosing screenshot capture itself; the screenshot method runs only after a driver session exists.
  • The element screenshot fails: Confirm navigation completed and the selector identifies an element in the current page. A misspelled selector or a page that has not yet rendered the target can prevent locating it.
  • The image is not the entire page: The basic driver call is documented for the current browsing context, not as a universal full-page guarantee. Check the support and behavior for your specific browser, driver, and Selenium version.
  • The image contents differ between runs: A screenshot records the browser state at capture time. Ensure the page has reached the state you intend to record before calling the screenshot method; the cited examples do not define a universal page-readiness wait strategy.
  • JavaScript output cannot be opened as an image: The documented JavaScript flow receives Base64 image data. Write it using Base64 decoding, as in the example, rather than treating the encoded text as raw image bytes.

Reliability, performance, and cost considerations

Selenium screenshots are browser captures, so your script must start and control a browser before it can save the image. For a single capture, keep the flow simple: navigate, reach the intended page state, capture, and close the driver. When captures run repeatedly, clean shutdown matters because each run manages a browser session; measure runtime and resource use in the browser and driver environment you actually deploy rather than assuming a universal capture time.

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

The official documentation patterns establish the capture calls, but do not provide a general performance figure, file-size estimate, or cross-browser reliability guarantee. Those depend on the page and execution environment. Test the precise browser, driver, Selenium binding version, and target pages that matter to your workflow—especially if the output must include content beyond the current view.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request can return a PNG, JPEG, WebP, or PDF. For example, save a WebP screenshot of a page with cURL:

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

See the ScreenshotNeo API documentation for request options. Its clean-shot flow accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response identifies the page verdict and billing status in headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan.

Which method should you use?

For an automated browser workflow that already uses Selenium, use driver.save_screenshot(path) for the current browsing context or element.screenshot(path) for one located element. Choose the binding-specific output method when working in another language, and verify browser/driver behavior when the requirement is full-page capture. If you do not want to configure and run a browser yourself, the API call above is an alternative way to request a screenshot.

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.

Frequently Asked Questions

Does the Selenium screenshot endpoint return PNG bytes directly?

The WebDriver screenshot endpoint returns Base64-encoded image data. Selenium bindings handle that data differently; for example, JavaScript examples write the Base64 output to a file.

Does Selenium’s PDF feature have the same headless behavior as screenshots?

No. Selenium’s documentation specifies a headless requirement for its page-to-PDF capability on Chromium browsers; that requirement is not established for ordinary image screenshots.

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.