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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

If WebElement.screenshot() saves the wrong part of the page, first compare it with a full-window screenshot taken at the same moment. That single comparison tells you whether the page itself is wrong or Selenium’s element-capture crop is wrong. Then check CSS zoom and transforms, viewport-to-image scaling, and browser-driver support before attempting a coordinate correction.

Selenium’s Python API exposes element.screenshot(filename), element.screenshot_as_png, and element.screenshot_as_base64. The filename method writes a PNG and returns a Boolean indicating whether the file was saved; a true return value does not prove that the pixels contain the intended region.

Element screenshots and window screenshots are different operations

driver.save_screenshot("window.png") captures the current browser window. element.screenshot("element.png") asks the browser driver to capture the element’s rendered region. The second operation depends on driver support and coordinate conversion, so a correct window image can coexist with an incorrectly cropped element image.

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

Use both calls while the page is in exactly the same state:

#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • 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 selenium import webdriver
from selenium.webdriver.common.by import By

# driver is already configured and the page is loaded
element = driver.find_element(By.CSS_SELECTOR, "your-selector")
window_ok = driver.save_screenshot("window.png")
element_ok = element.screenshot("element.png")
print("window saved:", window_ok)
print("element saved:", element_ok)
print("element rect:", element.rect)
print("element PNG bytes:", len(element.screenshot_as_png))

Open both files. If the full-window image also shows the wrong layout, investigate page state, scrolling, responsive breakpoints, lazy loading, or timing. If the window is correct but the element image is offset or incorrectly sized, continue with the capture-path checks below.

Check CSS zoom and transforms first

CSS zoom can change the crop coordinate system

SeleniumHQ issue #11655 reports a wrong-region element screenshot after document.body.style.zoom = 1.5. The reported environment was Selenium 4.8.0, Chrome 110.0.5481.96, ChromeDriver 110.0.5481.77, Debian GNU/Linux 10, and headless mode. The same report says a full-window screenshot looked correct.

This is evidence of a failure on that particular older setup, not proof that every current Selenium, Chrome, or driver release mishandles CSS zoom. Record your versions before assigning blame, and test once with zoom removed:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
zoom_state = driver.execute_script(
    "return {body: document.body.style.zoom, html: document.documentElement.style.zoom};"
)
print(zoom_state)

driver.execute_script("document.body.style.zoom = '1'")
element.screenshot("element-no-zoom.png")

If the no-zoom capture is correct, keep zoom disabled during capture when your application permits it, or isolate the page in a minimal reproduction and upgrade the browser/driver/Selenium combination. Do not assume that a fixed multiplier will work across machines.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • 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

Inspect transforms and scaled ancestors

transform: scale(), translated ancestors, and other layout transforms can make the visual pixels differ from the element’s ordinary CSS rectangle. Inspect the element and its ancestors:

details = driver.execute_script("""
const el = arguments[0];
const chain = [];
for (let n = el; n; n = n.parentElement) {
  const s = getComputedStyle(n);
  chain.push({tag: n.tagName, transform: s.transform, zoom: s.zoom});
}
return {rect: el.getBoundingClientRect().toJSON(), chain};
""", element)
print(details)

Capture with transforms temporarily disabled if you control the test page, then compare the result. A transform may also alter clipping or move an element outside the visible viewport; that is a layout condition to resolve, not a reason to invent a universal scale factor.

Measure CSS rectangles against actual PNG pixels

Wrong size and wrong position reports often come from mixing CSS pixels, device pixels, and PNG pixels. Capture viewport metrics and the element rectangle, then inspect the output image dimensions with an image library:

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.
import io
from PIL import Image

metrics = driver.execute_script("""
const r = arguments[0].getBoundingClientRect();
return {
  rect: {x:r.x, y:r.y, width:r.width, height:r.height},
  innerWidth: window.innerWidth,
  innerHeight: window.innerHeight,
  dpr: window.devicePixelRatio,
  scrollX: window.scrollX,
  scrollY: window.scrollY
};
""", element)

png = element.screenshot_as_png
with Image.open(io.BytesIO(png)) as im:
    print("PNG pixels:", im.size)
print("browser metrics:", metrics)

Compare measured values in the same run. A community report describes screenshot/viewport dimension mismatch as a possible source of wrong location and scale, but it does not establish a general conversion formula. Device scale factor, headless settings, operating-system scaling, browser zoom, and driver implementation can all matter. Measure the ratio in your environment rather than copying a factor from another system.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • 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.

Verify versions, mode, and element-capture support

Record the complete environment whenever a capture is wrong:

  • Selenium Python package version.
  • Browser and browser-driver versions.
  • Operating system and architecture.
  • Headless or headed execution.
  • Window and viewport dimensions.
  • Device scale factor and browser/page zoom.
  • Relevant CSS transforms and scroll position.

Element screenshot support is not uniform among browser vendors; SeleniumLibrary’s implementation notes that support is limited. A driver can therefore implement window screenshots reliably while producing incomplete or incorrectly positioned element captures. Check the support level for your exact browser-driver pair and test a small page containing one fixed-size element before changing production code.

Use a validated full-window crop as a fallback

When element capture is unsupported or remains incorrect, take a window screenshot and crop it yourself. The critical requirement is validating CSS-to-image coordinates from measured data; never assume CSS pixels equal PNG pixels.

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.
from PIL import Image

# Save the page and obtain the same-run geometry
driver.save_screenshot("window.png")
box = driver.execute_script("""
const r = arguments[0].getBoundingClientRect();
return {x:r.x, y:r.y, width:r.width, height:r.height};
""", element)

with Image.open("window.png") as source:
    image_w, image_h = source.size
    viewport = driver.execute_script(
        "return {w: window.innerWidth, h: window.innerHeight};"
    )
    sx = image_w / viewport["w"]
    sy = image_h / viewport["h"]
    left = round(box["x"] * sx)
    top = round(box["y"] * sy)
    right = round((box["x"] + box["width"]) * sx)
    bottom = round((box["y"] + box["height"]) * sy)
    left = max(0, min(left, image_w))
    top = max(0, min(top, image_h))
    right = max(left, min(right, image_w))
    bottom = max(top, min(bottom, image_h))
    source.crop((left, top, right, bottom)).save("element-cropped.png")
    print("scale:", sx, sy, "crop:", (left, top, right, bottom))

This approach is only as good as the geometry and scale measurements. Sticky headers, scrolling, fractional coordinates, device-pixel rounding, and an element partly outside the viewport need explicit handling. For full-page targets, scroll the element into a known position or use a capture method designed for full-page output, then verify the crop visually.

Make the capture deterministic

Wait for the element and its content

An element can exist before its fonts, images, or client-rendered content are ready. Wait for visibility and any application-specific readiness condition, then capture:

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • 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
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, "your-selector")
))
wait.until(lambda d: d.execute_script("return document.fonts.status") == "loaded")
driver.execute_script("window.scrollTo(0, 0)")
element.screenshot("stable-element.png")

Replace the font check with a condition appropriate to your site when web fonts are not used. Also wait for lazy images or animations to settle; otherwise a technically correct crop may still contain an intermediate visual state.

Check overlays and clipping

Cookie dialogs, chat widgets, sticky overlays, and modal backdrops can cover the target or change its measured rectangle. Inspect the window screenshot for these layers. Dismiss them in the test flow, hide them with test-only CSS, or capture after the overlay is gone. A screenshot file can be valid while its visible content is not the content your test intended.

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

Diagnose file failures separately from image failures

element.screenshot(filename) returns false when Selenium cannot save the file. Check the Boolean, path permissions, parent directory, and available disk space independently of what the image contains:

from pathlib import Path

path = Path("artifacts/element.png")
path.parent.mkdir(parents=True, exist_ok=True)
ok = element.screenshot(str(path))
print("saved:", ok, "exists:", path.exists(), "bytes:", path.stat().st_size if path.exists() else 0)
if not ok:
    raise RuntimeError("Selenium did not save the element screenshot")

If the method reports success but the crop is wrong, the problem is rendering, geometry, or driver behavior—not file writing. For in-memory workflows, use screenshot_as_png or screenshot_as_base64 and log the byte length before decoding.

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

Or skip the browser setup

For server-side captures, ScreenshotNeo provides a single HTTP request that returns PNG, JPEG, WebP, or PDF. It removes cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server includes take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

cURL

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

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

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}`);
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const data = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', data));

See the ScreenshotNeo documentation for request options. You can set a CSS selector, full-page mode, viewport or device preset, retina scale, dark mode, custom CSS and JavaScript, waits, blocked resources, headers, cookies, user agent, timezone, geolocation, image resizing, caching TTL, signed links, asynchronous webhooks, PDF settings, and bulk capture of up to 100 URLs per call. Plans include 1,000 free screenshots per month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【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.

Troubleshooting checklist

  • Window and element are both wrong: fix page timing, scroll position, responsive layout, or overlays first.
  • Window is right, element is offset: test without CSS zoom and transforms; then verify driver support and coordinate metrics.
  • Element dimensions are wrong: compare PNG dimensions with viewport dimensions and device scale factor from the same run.
  • Only headless fails: repeat headed and headless with identical window dimensions and record both environments.
  • Crop changes between runs: wait for fonts, images, animations, and client rendering; freeze animations where possible.
  • File is missing: inspect the Boolean return, directory permissions, and disk space.
  • No reliable fix emerges: create a minimal page, preserve version details, and use a measured full-window crop.

FAQ

Does element.screenshot() capture the entire page?

No. It targets the current element’s rendered region. Use a window or full-page capture when the required output is the whole document.

Should I multiply coordinates by devicePixelRatio?

Not automatically. Compare actual PNG and viewport dimensions in the same execution; the measured ratios are safer than a hard-coded assumption.

Is CSS zoom always a Selenium bug?

No. A historical SeleniumHQ report demonstrates one wrong-region case, but it does not establish that current versions universally fail with CSS zoom.

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.

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