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.

Locate the intended Selenium WebElement, wait until it is visible, and pass that element to AShot’s element overload:

WebElement element = driver.findElement(By.cssSelector("#my_element"));
Screenshot screenshot = new AShot().takeScreenshot(driver, element);

AShot first obtains a page screenshot, calculates the element’s position and dimensions, and crops the source image. If the crop is shifted or scaled, the usual causes are coordinate lookup, page state, or device-pixel-ratio differences—not the CSS selector itself.

What you need before capturing an element

  • A Java project with Selenium WebDriver and AShot on the classpath.
  • A browser driver that can load the target page and execute JavaScript.
  • A stable locator for the element you want to capture.
  • A wait for the element’s final visual state, including images, fonts, animations, or client-rendered content that affect its size.

The AShot repository README uses Maven coordinates ru.yandex.qatools.ashot:ashot:1.5.4. That is the version shown in the README example, not a guarantee that it is compatible with every current Selenium release, browser, or driver. Test the combination used by your build.

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.

Maven dependency

<dependency>
  <groupId>ru.yandex.qatools.ashot</groupId>
  <artifactId>ashot</artifactId>
  <version>1.5.4</version>
</dependency>

If your project uses Gradle, declare the same group, artifact, and version in its dependencies block. Keep the version in one place so it can be changed when you validate a newer fork or compatibility combination.

#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

Capture one element with a complete Selenium example

This example opens a page, waits for #my_element, scrolls it into view, captures only that element, and writes a PNG. Replace the URL and selector with your own values.

import java.io.File;
import java.time.Duration;
import javax.imageio.ImageIO;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;

public class ElementShot {
    public static void main(String[] args) throws Exception {
        WebDriver driver = new ChromeDriver();
        try {
            driver.get("https://example.com");

            WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
            WebElement element = wait.until(
                ExpectedConditions.visibilityOfElementLocated(
                    By.cssSelector("#my_element")));

            ((JavascriptExecutor) driver).executeScript(
                "arguments[0].scrollIntoView({block:'center', inline:'nearest'});",
                element);

            Screenshot screenshot = new AShot()
                .takeScreenshot(driver, element);

            ImageIO.write(
                screenshot.getImage(),
                "PNG",
                new File("element.png"));
        } finally {
            driver.quit();
        }
    }
}

The example assumes your Selenium setup can create a ChromeDriver. Driver provisioning and browser versions are outside AShot, so configure them according to your environment. With older Selenium APIs, the WebDriverWait constructor may use an integer timeout instead of Duration.

Choose a locator that identifies the visual component

Prefer a stable ID or a dedicated data attribute over a long, position-dependent XPath. If several nodes match, use an explicit index only when the page contract makes that ordering reliable. Log the element’s tag, class, location, and size before capture; this separates a locator mistake from a cropping mistake.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Wait for the final state, not just DOM presence

presenceOfElementLocated only proves that a node exists. For screenshots, visibility is normally a better minimum. Add a project-specific wait for a loading class to disappear, an image’s complete property, a chart canvas to receive data, or an animation to finish. AShot crops the pixels available at capture time, so a correct locator can still produce an incomplete image if the page is changing.

How AShot finds the crop coordinates

AShot’s documented workflow is: take a page screenshot, obtain the target element’s position and dimensions, then crop the original image. The coordinate provider is therefore as important as the selector.

Coordinate method When to use it Important qualification
Default jQuery provider First choice when the page and driver execute the injected JavaScript normally. AShot’s README says jQuery is used by default; failures in script execution can make the returned position unreliable.
WebDriverCoordsProvider Use when the default provider does not agree with the browser driver. It obtains coordinates through the WebDriver API rather than the default jQuery route.
Custom CoordsProvider Use when your application needs a site-specific calculation or neither built-in provider handles the layout. You must validate the resulting rectangle against the rendered page and output image.

Try the WebDriver coordinate provider

import ru.yandex.qatools.ashot.coordinates.WebDriverCoordsProvider;

Screenshot screenshot = new AShot()
    .coordsProvider(new WebDriverCoordsProvider())
    .takeScreenshot(driver, element);

Make this change when the element is located correctly but the crop is consistently offset, especially after a driver or browser change. Compare the element’s getLocation() and getSize() values with the visible rectangle in the output rather than switching providers at random.

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.

When a custom provider is justified

A custom provider is useful for an application with unusual transforms, nested scrolling regions, or a driver-specific coordinate behavior. Keep the provider small and test it against elements near each edge of the viewport, inside nested containers, and below a scroll position. The provider should return coordinates in the same pixel space that AShot’s source screenshot uses.

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

Viewport, scrolling, and layout conditions that change the result

Scroll the element into a known position

Scrolling before capture makes sticky headers, lazy content, and nested scroll areas easier to diagnose. Centering the element, as in the example, reduces the chance that a fixed toolbar covers its top edge. If the element lives inside a scrollable panel, scroll that panel as well; scrolling the window alone may leave the node clipped.

Account for fixed and animated UI

A fixed header can overlap a target after scrolling. Hide or dismiss it in test setup, or scroll to a position where it does not cover the element. Freeze or wait out transitions when a moving edge would make repeated crops differ. Capture after the page reaches the same state used for visual comparison.

Frames and shadow roots

For an element inside an iframe, switch into the frame before finding the element, then capture while that frame is active:

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
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe")));
WebElement element = new WebDriverWait(driver, Duration.ofSeconds(15))
    .until(ExpectedConditions.visibilityOfElementLocated(
        By.cssSelector("#my_element")));
Screenshot screenshot = new AShot().takeScreenshot(driver, element);
driver.switchTo().defaultContent();

For shadow DOM, obtain the element through the shadow root using the Selenium APIs supported by your version. Verify the resulting crop in the actual browser; coordinate behavior can differ from ordinary light-DOM elements.

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

Device-pixel ratio and Retina scaling

CSS pixels and screenshot pixels are not always one-to-one. A historical issue discussion described a Retina display with device pixel ratio 2 producing an image four times larger than expected. The reporter said ShootingStrategies.viewportRetina(100, 0, 0, 2) worked in that particular setup. Treat this as a setup-specific workaround, not a universal fix.

import ru.yandex.qatools.ashot.ShootingStrategies;

Screenshot screenshot = new AShot()
    .shootingStrategy(ShootingStrategies.viewportRetina(100, 0, 0, 2))
    .takeScreenshot(driver, element);

Before adopting a scale value, record the browser’s device-pixel ratio, the element’s CSS dimensions, and the image dimensions returned by AShot. Then verify that the crop has the expected physical pixel size on the same operating-system display settings used in production. A scale mismatch can make a correctly positioned crop look wrong simply because it is enlarged or reduced.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot a crop that is not the correct element

Symptom Likely cause Fix
Exception while locating the element The selector does not match, the page has not loaded, or the node is inside a frame. Log the URL and selector, wait for visibility, inspect matching-node count, and switch into the correct frame before locating.
The image shows the right area but is shifted Coordinate lookup disagrees with the screenshot’s pixel space; scrolling or a fixed header may also be involved. Scroll to a known position, compare getLocation() with the rendered rectangle, and try WebDriverCoordsProvider.
The crop is the wrong size by a constant factor Device-pixel ratio or Retina scaling differs between the test machine and the expected output. Measure CSS and bitmap dimensions, inspect the actual ratio, and test a matching shooting strategy rather than copying a value blindly.
The crop contains a loading spinner or missing image The element was visible before its contents settled. Wait for the relevant network-driven state, image completion, chart rendering, or loading class removal.
Only part of the element appears The element is clipped by a viewport or nested scrolling container. Scroll the correct container, remove an overlay, and check whether the element’s client rectangle is fully visible.
Results changed after a browser upgrade AShot, Selenium, the driver, or the browser may have changed coordinate behavior. Pin the tested combination, rerun a small set of known crops, and validate compatibility before upgrading a larger suite.
The file is not created The output directory is missing or the process lacks write permission. Use an absolute path, create the directory first, and check the boolean or exception returned by ImageIO.write.

A 2019 issue reported incorrect selected-element screenshots with Chrome 74 on a MacBook Pro. That report confirms the problem in that setup; it does not prove a universal AShot defect or a confirmed fix. Reproduce the behavior with your exact browser, driver, operating system, and page before drawing a broader conclusion.

Make captures repeatable in CI

  • Use a fixed viewport, browser zoom, font set, and device-pixel ratio where possible.
  • Wait for fonts, images, charts, and animations that affect geometry.
  • Record browser, driver, Selenium, AShot, operating-system, and viewport versions with each failure.
  • Save the full page screenshot as a diagnostic artifact when an element crop is wrong; comparing the source and crop reveals whether the error is in rendering or coordinates.
  • Run a small calibration page containing elements at the top, bottom, inside a nested scroller, and inside an iframe after changing providers or dependencies.
  • Keep output naming deterministic, but include a test identifier so parallel jobs do not overwrite one another.

AShot does not establish a current Selenium/browser compatibility matrix in its README. Treat the README’s 1.5.4 dependency as a starting point and verify your own stack with representative pages.

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.

Or skip the browser setup

For a server-side screenshot of a URL, ScreenshotNeo provides a single GET request that returns PNG, JPEG, WebP, or PDF. It is different from an in-process Selenium crop: before capture it accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Each step can be turned off.

Only clean shots are billed. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to 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://example.com 
  -o shot.webp

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://example.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://example.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

See the ScreenshotNeo documentation for request options and response details. The service also supports full-page capture with lazy images loaded, CSS-selector element capture, device presets or custom viewports, dark mode, retina scale, custom CSS and JavaScript, clicks, waits, hidden selectors, request and resource blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, usage data, and an OpenAPI specification. Parameter names used by other screenshot APIs also work, which can simplify migration.

Plans and cost

Plan Allowance and price
Free 1,000 shots per month; no card required
Starter $5 for 3,000 shots
Growth $15 for 15,000 shots
Pro $39 for 60,000 shots
Scale $99 for 250,000 shots
Business $249 for 1,000,000 shots

Every feature is included on every plan, and yearly billing gives two months free. If you want to test URL capture without installing a browser or driver, create a free ScreenshotNeo account for 1,000 screenshots a month with no card.

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.