October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix 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 desk4 min

How to Take a Partial Screenshot With Selenium WebDriver in Python

Use Selenium's WebElement screenshot method to save a single page element as PNG, or return its image as bytes or base64.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To screenshot one part of a page with Selenium in Python, locate the element and call its screenshot() method. It saves that element as a PNG:

from selenium.webdriver.common.by import By

element = driver.find_element(By.CSS_SELECTOR, "main .result-card")
element.screenshot("partial.png")

Here, driver is an already-created Selenium WebDriver instance. Replace the example CSS selector with one that matches the element you want to capture.

Save a screenshot of one element

After navigating to the page and ensuring the target is in the state you want to capture, find it with a stable locator and call WebElement.screenshot():

from selenium.webdriver.common.by import By

# driver is an already-created Selenium WebDriver instance.
element = driver.find_element(By.CSS_SELECTOR, "main .result-card")
saved = element.screenshot("partial.png")

if not saved:
    raise OSError("Could not save the element screenshot")

The filename should end in .png. The method returns True if it saves successfully and False if it encounters an I/O error. See Selenium’s WebElement Python API for the method details.

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

Choose a reliable locator

The selector above is illustrative. Prefer a page-specific ID or CSS selector that identifies the intended element consistently. If the selector matches the wrong element, Selenium will capture that match instead; check the locator against the page under test.

Wait for the intended page state

Locate and capture the element only after the page has reached the state you intend to record. Dynamic pages may render or update content after navigation. Selenium’s screenshot API documents the capture operation, but there is no single wait strategy established for every page or application; choose a wait condition that matches your page.

Choose the right capture scope and output

“Partial screenshot” can mean an element image, a crop of the visible window, or a full-document image. Selenium’s element method directly addresses the first case. These scopes and output forms are not interchangeable:

What you need Python API Output or scope
One located page element element.screenshot("element.png") Saves the element screenshot as a PNG file.
PNG image data for one element element.screenshot_as_png Returns PNG bytes for downstream code.
Base64 representation for one element element.screenshot_as_base64 Returns a base64 string.
Current browser window driver.get_screenshot_as_file("window.png") Saves a screenshot of the current window, not a full-document or element-only screenshot.
Full document in Firefox driver.get_full_page_screenshot_as_file(...) Firefox’s Python API documents separate full-document screenshot methods.

For driver-level current-window methods, see Selenium’s WebDriver Python API. Firefox full-document methods are documented in the Firefox WebDriver Python API. Do not treat a current-window capture as a full-page screenshot.

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

Use PNG bytes or base64 when a file is not the next step

Use element.screenshot_as_png when another part of your program needs image bytes, or element.screenshot_as_base64 when the data must be represented as base64. The WebElement API documents all three element screenshot forms.

When the target is an arbitrary rectangle

An element screenshot is appropriate when the region corresponds to a DOM element. If you need a pixel rectangle that does not correspond to an element, the cited Selenium APIs do not establish a general crop method; do not assume the element method captures arbitrary coordinates.

Troubleshoot an element screenshot

  • The file is missing or not written: check the output path and directory permissions, use a .png filename, and inspect the method’s Boolean return value.
  • The wrong area was captured: verify that the locator identifies the intended element on the current page and that it does not resolve to a different match than expected.
  • The image shows an earlier or incomplete page state: wait for the target content to reach the state you want before capturing. The appropriate condition depends on the application.
  • The result differs across layouts or browsers: inspect the page and browser state and verify the element and output. The cited API references do not establish universal guarantees for off-screen elements, clipping, or rendering behavior across drivers.
  • You expected the whole page: a driver-level screenshot is for the current window. Firefox documents separate full-document methods; use a method whose scope matches the desired image.
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 screenshot through an API rather than managing a Selenium browser session, ScreenshotNeo offers a one-request capture. Its cookie and consent handling removes known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. ScreenshotNeo also provides an MCP server with screenshot tools for AI agents.

For a full-page capture of a target URL, the cURL request is:

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Replace YOUR_API_KEY with your key and replace the target URL as needed. See the ScreenshotNeo API documentation for request options, including element capture. ScreenshotNeo is a website screenshot API and MCP server by Yorker Media; it is an alternative to Selenium when you want an API or agent-driven capture rather than setting up a browser in your own script.

The Free plan includes 1,000 shots per month with no card required; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does Selenium save a WebElement screenshot as a PNG?

Yes. The WebElement screenshot method saves a PNG file; use a filename ending in .png.

Can I use Selenium’s element screenshot method for any rectangular crop?

It is intended for a located page element. The cited APIs do not establish a general method for capturing arbitrary pixel coordinates that do not correspond to an element.

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.

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.