Recommended Free Tools
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use Selenium’s WebElement.screenshot() method after locating the element you need. In Python, the essential operation is:
from selenium.webdriver.common.by import By
element = driver.find_element(By.CSS_SELECTOR, "#target")
saved = element.screenshot("/absolute/path/element.png")
if not saved:
raise OSError("Could not save element screenshot")
This writes a PNG of the selected element instead of the entire browser window. Use a precise locator, make sure the element is rendered, and provide an absolute filename ending in .png.
What Selenium captures
element.screenshot() captures the current rendered WebElement. It is different from a WebDriver screenshot, which captures the current browser window. Selenium’s Python API documents the element method as saving a PNG file and returning False when an I/O error prevents the save; otherwise it returns True. The documented recommendation is to use a full path for the filename.
The method does not select an element by itself. You first call find_element(), which returns the first match. If a page contains several cards, buttons, or banners matching your selector, make the selector specific enough that the first match is the one you intend to capture.
Complete Python example
The following example starts Chrome, opens a page, waits for a target element, scrolls it into view, verifies visibility, and writes the image to an absolute path.
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = "https://example.com"
output = Path("element.png").resolve()
driver = webdriver.Chrome()
try:
driver.get(url)
wait = WebDriverWait(driver, 20)
element = wait.until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "#target"))
)
# Selenium documents this property as scrolling the element into view.
element.location_once_scrolled_into_view
if not element.is_displayed():
raise RuntimeError("The target element is not displayed")
saved = element.screenshot(str(output))
if not saved:
raise OSError(f"Selenium could not write {output}")
print(f"Saved {output}")
finally:
driver.quit()
Replace https://example.com and #target with your page and selector. The explicit visibility wait prevents a common race in which the DOM node exists before its content is displayed.
Choose a reliable locator
Selenium’s Python API supports ID, name, XPath, CSS selector, class name, tag name, link text, partial link text, and relative locators. CSS is often convenient for a single element, but the best strategy is the one that uniquely identifies the intended node and remains stable when the page changes.
Free tools Windows power users keep installed
One-click scans. No signup required.
ID and CSS selectors
element = driver.find_element(By.ID, "invoice-total")
# Equivalent CSS form:
element = driver.find_element(By.CSS_SELECTOR, "#invoice-total")
Prefer an ID when it is unique and stable. For a component with a meaningful data attribute, a selector such as [data-testid='price-card'] can avoid coupling the test to presentation classes.
XPath and other strategies
element = driver.find_element(By.XPATH, "//section[@aria-label='Summary']")
element = driver.find_element(By.NAME, "email")
element = driver.find_element(By.CLASS_NAME, "result-card")
Class, tag, link-text, and partial-link-text locators can match more than one node. If that happens, Selenium captures only the first match. Use a parent-child relationship, an attribute, or a more specific CSS/XPath expression when uniqueness matters.
Save to disk, bytes, or base64
Save a PNG file
Pass the absolute filename directly to screenshot(). Keep the .png extension and check the Boolean result so a permissions or path problem does not go unnoticed.
Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
path = "/tmp/product-card.png"
if not element.screenshot(path):
raise OSError("Element screenshot failed")
Keep PNG bytes in memory
Use screenshot_as_png when you want to upload, hash, or process the image without creating an intermediate file.
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 →png_bytes = element.screenshot_as_png
with open("element.png", "wb") as image_file:
image_file.write(png_bytes)
Get a base64 string
screenshot_as_base64 returns the PNG as a base64 string, useful when another API expects text.
encoded = element.screenshot_as_base64
The element API produces PNG output. If you need another image format, convert the PNG after capture with an image-processing library rather than changing the filename extension.
Visibility, scrolling, and dynamic pages
Scroll an off-screen element into view
Selenium documents location_once_scrolled_into_view as causing the element to scroll into view. Access it immediately before capture when the target starts below the viewport:
element.location_once_scrolled_into_view
saved = element.screenshot("/absolute/path/target.png")
Scrolling does not replace a visibility check. is_displayed() is Selenium’s documented visibility check; use it to fail clearly when a matching node is hidden.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Wait for the rendered state
Single-page applications often insert a node before its text, images, or styles finish loading. Wait for visibility, a distinctive class, or another state that means the component is ready. A fixed sleep can work for a quick diagnostic but is less reliable than an explicit wait because network and rendering times vary.
from selenium.webdriver.support import expected_conditions as EC
ready = WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "#target"))
)
ready.screenshot("/absolute/path/target.png")
Visibility and scrolling behavior can still vary with page code and browser driver details. The Selenium API documentation does not promise an identical result for every hidden-element or driver edge case, so treat a failed or blank capture as a condition to diagnose rather than silently accepting it.
Elements inside frames
If the target is inside an iframe, switch into that frame before locating it, then switch back when finished:
frame = driver.find_element(By.CSS_SELECTOR, "iframe.payment")
driver.switch_to.frame(frame)
try:
element = WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "#target"))
)
element.screenshot("/absolute/path/target.png")
finally:
driver.switch_to.default_content()
The selector is evaluated in the current document context. Looking for a frame’s child element before switching into the frame produces a “no such element” error.
Element screenshot versus full-window screenshot
| Need | Use | Result |
|---|---|---|
| One card, chart, button, or other WebElement | element.screenshot(path) |
PNG of the selected element |
| PNG bytes in memory | element.screenshot_as_png |
Bytes, no file required |
| Base64 image data | element.screenshot_as_base64 |
Base64-encoded PNG |
| Current browser window | driver.save_screenshot(path) or driver.get_screenshot_as_file(path) |
PNG of the current window |
WebDriver’s window methods are the right choice when the page context matters—for example, a full checkout screen or a debugging record. They do not substitute for an element capture when you need a tightly cropped component.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
Common failures and fixes
“No such element”
- Cause: the selector is wrong, the element has not been inserted, or the element is inside an iframe.
- Fix: confirm the selector in browser developer tools, wait for the expected condition, and switch to the correct frame before calling
find_element().
The first matching element is wrong
- Cause:
find_element()returns the first match. - Fix: narrow the CSS/XPath expression or locate a unique parent before selecting the child.
The screenshot is blank or visually incomplete
- Cause: capture happened before the component rendered, the node is hidden, or lazy content has not loaded.
- Fix: wait for visibility and the component’s ready state, scroll into view, and verify
is_displayed(). For an element that changes after an asynchronous request, wait on a specific text, attribute, or loading class.
“Could not save” or a false return value
- Cause: the destination directory does not exist, the process lacks write permission, or the path is not usable.
- Fix: resolve an absolute path, create the directory first, check permissions, and test the Boolean returned by
screenshot().
The file has the wrong format
- Cause: element screenshots are documented as PNG output.
- Fix: save as PNG, then convert the resulting bytes with your image library if JPEG or WebP is required.
Capture differs between runs
- Cause: responsive layout, animations, fonts, or network-loaded content changed before capture.
- Fix: use a consistent browser window size, wait for a stable visual state, disable or finish animations in your test setup, and capture only after the same readiness condition each run.
Performance and reliability practices
- Reuse one driver session for related captures instead of starting a browser for every element.
- Use explicit waits with a sensible upper limit; this avoids both premature images and unnecessarily long runs.
- Capture the smallest required scope. Element screenshots create smaller files and make visual comparison easier than full-window images.
- Use deterministic, unique filenames when running tests in parallel so workers do not overwrite one another.
- Keep the original PNG bytes when an audit trail matters; convert only for downstream systems that require another format.
- Record the URL, selector, viewport, and timestamp alongside the image so a later failure can be reproduced.
The Selenium documentation reviewed for this procedure covers the element and window APIs but does not establish a cross-browser compatibility matrix. Validate the exact browser-driver combinations used by your project rather than assuming identical edge-case behavior.
Version notes
The Python WebElement API documentation surfaced for Selenium 4.33.0 describes locator behavior, element screenshots, PNG bytes/base64, visibility, and scrolling. The WebDriver API documentation surfaced for Selenium 4.49.0 describes current-window screenshot methods. Because those references represent different Selenium documentation versions, check the API documentation that matches the version pinned in your environment when upgrading.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If you only need a clean image of a URL or a selected page element and do not need Selenium’s in-browser control, ScreenshotNeo provides a website screenshot API. Its request can return PNG, JPEG, WebP, or PDF; options include full-page capture with lazy images loaded, a CSS-selector element capture, custom viewport and device presets, retina scale, waits, custom JavaScript/CSS, hidden selectors, click actions, headers, cookies, user agents, authorization, timezone and geolocation, blocking ads or selected requests, resizing, caching with a chosen TTL, signed image links, asynchronous jobs with webhooks, bulk capture of up to 100 URLs per call, and a usage API.
Windows 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 reinstallCrashes, 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 minuteBefore capture, it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response reports the page verdict and billing result in X-Page-Verdict and X-Billed headers. ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
For a direct call, see the ScreenshotNeo documentation:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same endpoint can be called from Python:
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)
Or Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
The Free plan includes 1,000 shots per month without a card. Paid plans start at $5 for 3,000 shots; yearly billing provides two months free, and every feature is included on every plan. Create a free ScreenshotNeo account to get the monthly allowance.
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
FAQ
Does Selenium return an image object from screenshot()?
No. The file method returns a Boolean indicating whether the PNG could be written. Use screenshot_as_png or screenshot_as_base64 when you need image data in memory.
Can I use the element method for a full-page document?
It is intended for a selected WebElement. For the current browser window use WebDriver’s screenshot methods; full-page behavior depends on the capture approach and is separate from selecting one element.
What if the page has several identical components?
Make the locator unique or deliberately select the required match with a more specific relationship. The basic find_element() call captures only the first matching element.
Frequently Asked Questions
Does Selenium return an image object from screenshot()?
No. The file method returns a Boolean; use screenshot_as_png or screenshot_as_base64 for in-memory image data.
Can I use the element method for a full-page document?
It is intended for one WebElement. Use WebDriver’s window screenshot methods when you need the current browser window instead.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
What if a page has several identical components?
Make the locator unique or use a more specific relationship, because find_element() captures the first match.
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.

