Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Find the element with a stable locator and call its screenshot() method. Selenium scrolls the element into view, captures its bounding rectangle, and writes a PNG. In Python, pass an absolute .png path and check the Boolean result so file-system failures do not go unnoticed.
Capture one element instead of the whole browser window
Assuming driver is an already configured Selenium WebDriver, this is the shortest working pattern:
from pathlib import Path
from selenium.webdriver.common.by import By
# Locate the component you want to capture.
element = driver.find_element(By.CSS_SELECTOR, "#target")
# Selenium expects a full path ending in .png.
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}")
element.screenshot() returns True after a successful write and False for an I/O failure. The resulting file is a PNG containing the element’s bounding-box region, not the entire browser window.
What Selenium captures
The element’s bounding rectangle
The WebDriver element-screenshot command captures the visible region encompassed by the element’s bounding rectangle. It is a geometric crop: Selenium does not interpret the element’s text, chart series, or semantic content to create a custom shape. If you need to remove padding, combine several regions, or add annotations, capture the element first and process the PNG in a separate image-processing step.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute#1 Best Overall
- FULL HD IPS DISPLAY - Enjoy vibrant, crystal-clear images with 178-degree wide-viewing angles
- AMD RYZEN 3 30 PROCESSOR - Everyday performance you can count on; Multitask, stream, game casually, and edit photos smoothly with responsive power and vibrant HDR visuals
- ENJOY UP TO 14 HOURS AND 15 MINUTES OF BATTERY LIFE - HP Fast Charge restores battery from 0 to 50% in approximately 45 minutes
- AMD RADEON 610M GRAPHICS - Experience smooth entertainment; Built for streaming and multitasking, enjoy realistic visuals and efficient performance for work and play
- STORAGE AND MEMORY - 512 GB PCIe NVMe M.2 SSD offers fast speed and efficient storage; and 8 GB LPDDR5 RAM memory boosts performance with higher bandwidth
Automatic scrolling
If the target is outside the viewport, the element screenshot command scrolls it into view before drawing its rectangle. The page may therefore be at a different scroll position after the call. Fixed headers, sticky toolbars, or overlays can still affect what is visible inside that rectangle; handle those in the page state before capturing.
PNG output
The Python API documents the filename as a full path ending in .png. Keep that extension even when the output is destined for another format. If you need JPEG or WebP, convert the saved PNG afterward with your image library rather than changing the Selenium filename extension.
A complete, timing-safe Python example
Locate the component only after the page has rendered it. An explicit wait is preferable to an arbitrary sleep when a chart, result card, or receipt appears asynchronously.
from pathlib import Path
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# driver must already be created and navigated to the page.
selector = "#target"
wait = WebDriverWait(driver, 20)
element = wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR, selector))
)
output = Path("artifacts/target.png").resolve()
output.parent.mkdir(parents=True, exist_ok=True)
if not element.screenshot(str(output)):
raise OSError(f"Selenium could not write {output}")
print(f"Saved element screenshot to {output}")
presence_of_element_located confirms that the node exists. For a component whose pixels are populated later, wait for a more meaningful condition—such as a loaded-state class or a child selector—before calling screenshot(). The correct condition depends on the page; adding a fixed delay can make tests unnecessarily slow or still capture an incomplete component.
Recommended Free Tools
Choose a locator that will survive page changes
Selenium supports ID, CSS selector, XPath, name, class name, and tag name strategies. Prefer a stable ID or a purpose-built CSS hook when one is available.
Rank #2
- Intel Celeron N4120: 4 Cores & Threads, 1.1GHz Base Clock, Up to 2.6GHz Boost Clock, 4MB Cache, Intel UHD Graphics 600. The perfect combination of performance, power consumption, and value helps your device handle multitasking smoothly and reliably with four processing cores to divide up the work.
- 14" HD Display: 14.0-inch diagonal, HD (1366 x 768), micro-edge, anti-glare. See your digital world in a whole new way. Enjoy movies and photos with the great image quality and high-definition detail of 1 million pixels.
- Memory & Storage: 4 GB LPDDR4x & 64 GB eMMC Storage. Adequate high-bandwidth RAM to smoothly run multiple applications and browser tabs all at once. An embedded multimedia card provides reliable flash-based storage.
- Ports:2 x USB 3.0 Type-A,1 x USB 3.0 Type-C,1 x HDMI,1 x Headphone Jack
- Chrome OS: Chromebook is a computer for the way the modern world works, with thousands of apps. Enjoy the seamless simplicity that comes with Google Chrome and Android apps, all integrated into one laptop. It’s fast, simple, and secure.
ID
element = driver.find_element(By.ID, "invoice-total")
An ID is concise and usually less sensitive to layout changes.
CSS selector
element = driver.find_element(By.CSS_SELECTOR, "[data-testid='result-card']")
A dedicated data-testid or similar attribute avoids coupling the test to visual class names. A descendant selector can target a specific part of a larger component:
element = driver.find_element(
By.CSS_SELECTOR,
"article[data-testid='result-card'] .price"
)
XPath and other strategies
element = driver.find_element(By.XPATH, "//section[@aria-label='Summary']")
Use XPath, name, class, or tag locators when the markup makes them the most stable option. Avoid a long chain of positional indexes; a small DOM change can make it select the wrong node.
Save a file, return bytes, or encode the image
| Need | Python API | Result |
|---|---|---|
| Persist an artifact | element.screenshot(path) |
PNG file and a Boolean success result |
| Send image data to another Python function | 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 |
Use PNG bytes without touching disk
png_bytes = element.screenshot_as_png
send_to_storage(png_bytes) # Replace with your upload or processing function.
Use Base64 for an HTML or JSON payload
encoded = element.screenshot_as_base64
payload = {"image": encoded}
Choose the form based on the next operation. A file is convenient for CI artifacts, bytes avoid a temporary file, and Base64 is useful when the receiving interface accepts text.
Rank #3
- Stunning 15.6" FHD IPS Display: Experience crisp 1920x1080 resolution on this 15.6 inch laptop with an IPS panel that delivers wide viewing angles and vivid colors. The narrow-bezel design maximizes screen real estate for comfortable viewing on this Win 11 laptop, whether you're studying or working.
- Celeron J4105 Processor & 256GB SSD: Powered by a reliable Celeron J4105 processor paired with 12GB DDR4 memory and a fast 256GB M.2 SSD. This laptop computer supports SSD expansion up to 2TB and TF card expansion up to 1TB, so your storage grows with your needs. Delivers smooth multitasking for daily productivity.
- AI-Powered Win 11 Laptop: Built-in AI features enhance your productivity with smart assistance for writing, summarizing, and task management. Pre-installed with Win 11 and includes Office 365 subscription. This student laptop is backed by 1-year warranty and 24/7 customer support.
- All-Day 7000mAh Battery & 180° Hinge: The high-capacity 7000mAh battery keeps this laptop powered through long classes or meetings. The 180-degree lay-flat hinge lets you share your screen effortlessly during presentations. This durable laptop computer adapts to your dynamic workflow.
- Versatile Connectivity Hub: Equipped with USB 3.2, Type-C, Mini HDMI, and 3.5mm audio jack to connect all your peripherals. Stay online anywhere with high-speed 5G WiFi and Bluetooth 4.2. This college laptop keeps you connected at home, in the library, or on the go.
Element screenshot versus window screenshot
driver.save_screenshot() captures the current browser window. It includes everything visible in that window: navigation, unrelated components, and surrounding whitespace. element.screenshot() targets one WebElement and captures only its bounding region after Selenium brings it into view. Use the driver method for a visual record of the page state; use the element method for a chart, card, receipt, or other isolated component.
Make the capture reliable in automated runs
Wait for the right state
- Wait for the element to exist before locating it.
- For asynchronous widgets, wait for a page-specific ready signal rather than a guessed number of seconds.
- If a loading overlay can cover the component, wait for that overlay to disappear before taking the screenshot.
Prepare the viewport and page
- Use a consistent browser window size in visual tests so line wrapping and responsive breakpoints do not change between runs.
- Dismiss or hide overlays that obscure the target. Selenium will still capture the rectangle even if another layer is painted over it.
- Remember that scrolling is part of the element-screenshot operation; do not assume the page remains at its previous scroll position.
Make the destination deterministic
- Resolve an absolute path.
- Create the parent directory before calling Selenium.
- Use a unique filename when parallel tests might capture the same selector.
- Check the returned Boolean and fail the test or retry according to your artifact policy.
Common failures and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
NoSuchElementException |
The locator is wrong or the element has not been inserted yet. | Verify the selector in the inspected DOM and use an explicit wait for the element. |
Screenshot returns False |
The destination cannot be written, commonly because the directory is missing or permissions deny access. | Resolve a full path, create the parent directory, check permissions, and treat False as a failed capture. |
| Warning or failure about the extension | The filename does not end in .png. |
Use a PNG filename and convert the image later if another format is required. |
| Image shows a spinner or empty chart | The element exists before its contents finish rendering. | Wait for a page-specific loaded condition, not merely for the node to be present. |
| Image contains a cookie banner, chat bubble, or sticky header | Those pixels overlap the element’s visible rectangle. | Dismiss or hide the overlay before capture, or crop/process the PNG afterward. |
| Only part of a large component appears | The screenshot is the element’s bounding region as rendered; internal overflow may be clipped. | Capture a larger container, change the component’s layout before capture, or perform a separate image-processing step. |
| Capture differs between machines | Viewport, fonts, device scale, or page state differs. | Standardize browser configuration and wait for the same ready state before comparing artifacts. |
Performance, reliability, and test-design notes
Keep waits specific
A long global sleep delays every test and does not prove that the pixels are ready. An explicit wait tied to the target component lets fast pages proceed immediately while giving slower pages time to finish.
Capture only what you need
An element screenshot transfers and stores less image data than a full-window capture and produces cleaner visual-diff artifacts. If the requirement is to document the whole page, use the driver-level method instead of taking many overlapping element images.
Separate capture from post-processing
Selenium gives you the element’s PNG (or its bytes/Base64 representations). Cropping to a semantic subregion, adding labels, changing formats, or comparing pixels belongs in the next pipeline stage. Keeping that boundary makes failures easier to diagnose: first establish that Selenium captured the intended rectangle, then inspect image processing.
Rank #4
- Efficient Performance for Everyday Computing: Powered by Intel N150 processor with up to 3.6 GHz Intel Turbo Boost Technology, 6 MB L3 cache, 4 cores, and 4 threads, this HP laptop delivers responsive performance for web browsing, streaming, document editing, and multitasking. Paired with 4GB LPDDR5 RAM and 128GB UFS storage, it handles daily tasks smoothly. Includes 1-year Microsoft 365 Personal subscription for Word, Excel, PowerPoint, and cloud storage to maximize your productivity.
- 14-Inch HD Micro-Edge Display:Enjoy clear visuals on the 14-inch HD (1366 x 768) anti-glare screen with 250-nit brightness and 62.5% sRGB coverage. The micro-edge bezel delivers a 79% screen-to-body ratio in a compact design. An HP True Vision 720p HD camera with noise reduction and dual-array microphones supports clear video calls, remote work, and online learning.
- Modern Connectivity and Wireless Technology: Stay connected with Wi-Fi 6 (2x2) for faster wireless speeds and Bluetooth 5.4 for seamless pairing with accessories. Versatile port selection includes 1 USB Type-C 10Gbps with DisplayPort 1.2 for external displays, 2 USB Type-A 5Gbps ports for peripherals, 1 HDMI 1.4b port, 1 headphone/microphone combo jack, and 1 multi-format SD media card reader. Connect monitors, transfer files quickly, and expand your workspace with ease.
- All-Day Battery Life and Portable Design: Enjoy up to 11 hours of video playback, 7.5 hours of mixed usage, or 7.5 hours of wireless streaming on a single charge, perfect for students and professionals on the go. Weighing just 3.24 lb and measuring 12.76" x 8.86" x 0.71", this lightweight laptop fits easily in backpacks and bags. The stylish willow green top cover with matte finish and natural silver keyboard deck with vertical brushing pattern offer a modern, professional look.
- AI-Enhanced Productivity: Access Microsoft Copilot instantly with the dedicated Copilot key for faster assistance. AI Noise Reduction filters background sounds and improves voice clarity during calls. Dual speakers provide clear audio, while the full-size natural silver keyboard and HP Imagepad support comfortable typing and navigation.
Plan for I/O errors
Even when the locator and browser state are correct, a read-only workspace, missing directory, or invalid path can prevent a file from being written. Create directories up front, use absolute paths, check the Boolean return, and preserve the exception context in CI logs.
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 URL or a CSS-selected element as an image, ScreenshotNeo is a hosted screenshot API and MCP server for developers. It can accept a cookie or consent banner as a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.
Its capture options include selecting one element by CSS selector, waiting for a selector, delay, or network idle, loading lazy images for full-page shots, custom JavaScript and CSS, hidden selectors, device presets, viewport and retina scale, and PDF output. An MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
For a direct call, see the ScreenshotNeo API documentation:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
There is a free plan with 1,000 screenshots per month and no card required. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. Create a free ScreenshotNeo account to get started.
Best Value
- Efficient Intel Processor: Powered by Intel Celeron 5205U dual-core two-thread processor with a fixed 1.9GHz base frequency, 2MB Intel Smart Cache and advanced 14nm Comet Lake lithography. Integrated Intel UHD Graphics for 10th Gen Intel Processors delivers stable daily performance. It handles daily office tasks, web browsing, video streaming and light multitasking smoothly while featuring ultra-low power consumption for extended use.
- Fast Response Large Storage:Equipped with 12GB high-speed RAM to accelerate program loading and enable seamless multitasking. Built-in 256GB solid-state drive provides rapid boot and application launch speeds, offering ample storage space for your documents, software, photos and videos. Run daily productivity and multimedia applications without lag or slowdowns.
- 15.6" FHD IPS Eye-Care Display:This laptop features a 15.6-inch Full HD IPS panel with native 1920×1080 resolution and classic 16:9 widescreen ratio. Designed with slim 5mm ultra-narrow bezels, anti-glare coating and blue light filtering eye protection, it effectively reduces eye strain during long hours of studying, streaming or working, delivering vivid, immersive visual experiences. effectively reduce blue light and eye strain, bringing you immersive visual experience for watching videos and studying.
- Pre‑Installed Windows 11: Ready to Use Comes with a genuine Windows 11 system pre‑loaded, offering a clean, intuitive interface and broad software compatibility. Open the box, power on, and you're all set for school assignments, business reports, or daily computing needs.
- Rich Ports & Long Lasting Battery Life:Built-in 38Wh rechargeable battery and dual stereo speakers. Support Bluetooth 4.2 & 2.4G/5G dual-band WiFi for fast wireless connection. Equipped with Type-C, HDMI, 3.5mm audio jack, dual USB 3.0, Micro TF slot and DC charging port, meet your daily external device connection and office expansion needs.
FAQ
Can an element screenshot be transparent outside the element?
The Selenium API described here returns a PNG of the element’s rectangular region. It does not provide a separate “transparent outside the shape” mode; treat transparency or non-rectangular extraction as post-processing.
Does Selenium provide a direct JPEG or WebP element method?
The documented Python element methods produce PNG output, PNG bytes, or Base64-encoded PNG data. Convert the result after capture if your storage or publishing pipeline requires another format.
What should I verify when porting this code to another Selenium language binding?
Verify that binding’s current, versioned API before copying the Python method names. The protocol defines the element-capture behavior, but exact language-level method names and compatibility can differ.
Frequently Asked Questions
Can an element screenshot be transparent outside the element?
The Selenium API returns a PNG of the element’s rectangular region and does not expose a non-rectangular transparency mode. Apply that kind of extraction as post-processing.
Does Selenium provide a direct JPEG or WebP element method?
The documented Python methods produce PNG output, PNG bytes, or Base64-encoded PNG data. Convert the result afterward if another format is required.
What should I verify when porting this code to another Selenium binding?
Check the current, versioned documentation for that language binding before reusing Python method names. Protocol behavior is defined, but binding-level APIs can differ.
Free tools Windows power users keep installed
One-click scans. No signup required.
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.

