Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesUse Selenium’s WebElement.screenshot() method to save one element’s bounding rectangle instead of the whole browser window. Locate the element with a stable ID or CSS selector, wait until it is ready, provide an absolute .png path, create the destination directory, and check the Boolean result.
Capture one element in Selenium
This complete Python example assumes driver is an already configured Selenium WebDriver. It finds an element, saves its visible bounding region as a PNG, and fails loudly if the file cannot be written:
from pathlib import Path
from selenium.webdriver.common.by import By
# Assume driver is an already configured Selenium WebDriver.
element = driver.find_element(By.CSS_SELECTOR, "#target")
output = Path("artifacts/target.png").resolve()
output.parent.mkdir(parents=True, exist_ok=True)
saved = element.screenshot(str(output))
if not saved:
raise OSError(f"Could not save element screenshot to {output}")
print(f"Saved element screenshot to {output}")
element.screenshot(path) writes PNG data and returns True when the save succeeds. A False result indicates an I/O failure, so do not assume that the file exists merely because the command returned.
What Selenium captures
The WebDriver element-screenshot command captures the visible region enclosed by the element’s bounding rectangle. If the element is outside the viewport, WebDriver scrolls it into view before drawing that rectangle. This is different from taking a screenshot of the current browser window: the result is the element region, not the complete page.
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 reinstall#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
The capture is geometric. It includes the pixels inside the element’s rectangle; it does not understand that you may want only the text, a chart plot area, or one semantic subsection inside a larger element. For a custom crop, save the element image first and process it with an image library in a separate step.
Choose a reliable locator
Use a selector that identifies the intended component consistently between runs. An ID is usually the simplest choice:
element = driver.find_element(By.ID, "receipt")
CSS selectors are useful for classes, attributes, and component structure:
element = driver.find_element(By.CSS_SELECTOR, "article.result-card[data-id='42']")
Selenium’s Python binding also supports XPath, name, class-name, and tag-name strategies. Prefer a stable application attribute over a positional selector such as div:nth-child(4), which can change when the page layout changes.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Wait for the element before capturing
Finding an element and having a useful screenshot are separate events. A page can contain the element before its chart, image, fonts, or asynchronous data has finished rendering. Use an explicit wait for a condition that represents readiness rather than an arbitrary sleep.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 20)
element = wait.until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "#target"))
)
output = "/absolute/path/artifacts/target.png"
if not element.screenshot(output):
raise OSError(f"Screenshot could not be saved to {output}")
visibility_of_element_located confirms that the node is present and displayed. If your application exposes a stronger signal—such as a “loaded” class, a result count, or a chart canvas with data—wait for that signal as well. An element can be visible while still showing a spinner or an empty placeholder.
Save a file, bytes, or Base64
| Need | Python API | Result |
|---|---|---|
| Persist an image file | element.screenshot(path) |
PNG file and a Boolean success result |
| Pass image data to another Python API | element.screenshot_as_png |
PNG bytes |
| Embed or transport encoded data | element.screenshot_as_base64 |
Base64 text |
| Capture the current browser window | driver.save_screenshot(path) |
Window screenshot, not an element-only image |
For example, send PNG bytes directly to an image-processing function:
png_bytes = element.screenshot_as_png
with open("artifacts/target.png", "wb") as file:
file.write(png_bytes)
Use the Base64 property when the receiving system expects text, such as a JSON payload or a data URL.
Output-path rules that prevent failures
- Use an absolute path. Resolving a relative path with
Path(...).resolve()makes the destination unambiguous in CI and scheduled jobs. - Create the parent directory before calling Selenium. A missing directory is a common file-I/O failure.
- Keep the filename extension as
.png. Selenium documents the element screenshot result as PNG and warns when the extension does not match. - Check the returned Boolean and verify the file if your pipeline requires durable artifacts.
- Ensure the WebDriver process has write permission in the destination directory.
Element screenshot versus window screenshot
Choose the API based on the deliverable:
- One component: call
element.screenshot(). This is appropriate for a receipt, card, chart, table, or isolated UI component. - The visible browser window: call
driver.save_screenshot(). This includes the current window rather than only one element. - A custom subregion: capture the element, then crop or annotate the resulting PNG with a separate image-processing step.
Element screenshots do not automatically create a full-page image. They also do not promise a semantic crop around text or individual descendants.
Common errors and fixes
NoSuchElementException
Cause: the selector is wrong, the page has not loaded the component, or the element is inside a frame or shadow root. Fix: verify the selector in browser developer tools, wait for the element, and switch to the correct iframe before locating it. Shadow-DOM access requires the application’s supported shadow-root APIs.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
StaleElementReferenceException
Cause: a framework replaced the node after you located it. Fix: wait for the replacement to finish and locate the element again immediately before calling screenshot().
The image contains a spinner or blank chart
Cause: visibility occurred before asynchronous rendering completed. Fix: wait for a data-ready condition, a nonempty result, or a component-specific completion marker instead of using a fixed delay alone.
screenshot() returns False or no file appears
Cause: the path is invalid, its directory does not exist, or the process lacks permission. Fix: resolve an absolute path, create the parent directory, use a .png suffix, and check filesystem permissions.
The result includes more or less than expected
Cause: Selenium captures the element’s bounding rectangle, including its padding, borders, and visible descendants. Fix: choose a more precise element or crop the saved PNG afterward. CSS transforms and responsive layout can also change the rectangle, so use a consistent viewport when visual comparisons matter.
The target is outside the viewport
WebDriver scrolls the target into view for the element screenshot command. If the page uses sticky headers or overlays, inspect the resulting image and adjust the page state or target element when necessary.
Reliability and performance practices
- Set a deterministic browser window size for repeatable responsive layouts.
- Wait for the application state you actually need, not merely document presence.
- Capture after fonts, images, and canvas content have rendered when those pixels matter to the artifact.
- Use unique filenames in parallel test runs to avoid workers overwriting one another.
- Keep screenshots as bytes when the next step is an upload or image comparison; this avoids an unnecessary temporary file.
- Store failures with the page URL, selector, viewport, and exception so a flaky capture can be reproduced.
Element screenshots are normally smaller and faster to transfer than full-window images, but the browser still has to load and render the page. Network latency, JavaScript execution, large images, and test-grid distance usually dominate the total time.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Or skip the browser setup
ScreenshotNeo provides a website screenshot API and MCP server when you need a URL captured without maintaining Selenium. Its element option accepts a CSS selector, alongside full-page capture, lazy-image loading, device presets, custom viewports, retina scale, waits, custom CSS and JavaScript, click actions, hidden selectors, blocked resources, headers, cookies, user agents, timezone and geolocation controls, resizing, caching, signed links, asynchronous jobs, bulk capture, usage data, and PDF output.
One GET request returns a PNG, JPEG, WebP, or PDF. The API accepts consent banners before capture 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 response headers identify the page verdict and billing status.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for the selector and other request parameters. The same service can be used 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}`);
ScreenshotNeo also includes an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots each month without a card; paid plans start at $5 for 3,000 screenshots. Create a free ScreenshotNeo account.
Free tools Windows power users keep installed
One-click scans. No signup required.
FAQ
Can Selenium save an element as JPEG?
The Python element screenshot API documents PNG output. Save the PNG and convert it separately if another format is required.
Does an element screenshot include content below the fold?
The command captures the element’s bounding rectangle after scrolling it into view. It is not a general full-page capture; very tall or overflowed content may require a different capture strategy.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Should I use a fixed sleep?
No. An explicit wait tied to the component’s readiness is more dependable because rendering time varies between runs and environments.
Frequently Asked Questions
Can Selenium save an element as JPEG?
The Python element screenshot API documents PNG output. Save the PNG and convert it separately if another format is required.
Does an element screenshot include content below the fold?
The command captures the element’s bounding rectangle after scrolling it into view. It is not a general full-page capture; very tall or overflowed content may require a different capture strategy.
Should I use a fixed sleep?
No. An explicit wait tied to the component’s readiness is more dependable because rendering time varies between runs and environments.
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.

