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

Playwright scrolls a selected element into view automatically when you call locator.screenshot(). Use a locator for the element, and Playwright performs actionability checks, scrolls as needed, then captures an image clipped to that element. If you want the scroll request to be visible in your code, call scrollIntoViewIfNeeded() first. There is no documented option on locator screenshots that disables this automatic scroll.

Choose the screenshot scope first

The correct API depends on whether you need one element, the visible contents of a scrollable region, or the whole page.

API Output Scroll behavior
locator.screenshot() The matched element, clipped to its rendered size and position Checks actionability and scrolls the element into view before capture
page.screenshot({ fullPage: true }) A tall image of the page’s scrollable content Captures the page rather than a selector-clipped element

Use the locator API for a component such as a card, chart, invoice, or dialog. Use the page API when the requirement is a complete page image. A full-page screenshot is not a way to capture one selector without the locator’s clipping behavior.

Capture a selected element

Pass a CSS or XPath selector to page.locator(), then call screenshot(). The locator form is the recommended API; the older ElementHandle.screenshot() API is discouraged in the Playwright reference.

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.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • 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.
import { chromium } from 'playwright';

const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
await page.goto('https://example.com', { waitUntil: 'networkidle' });

const target = page.locator('[data-testid="report-card"]');
await target.screenshot({ path: 'report-card.png' });

await browser.close();

The call waits for the locator’s actionability checks. If the matched element is not completely visible, Playwright requests a scroll into view before taking the image. The resulting file contains the element, not the surrounding page.

Use a CSS or XPath locator

await page.locator('.invoice-summary').screenshot({ path: 'invoice.png' });
await page.locator('xpath=//section[@aria-label="Results"]').screenshot({ path: 'results.png' });

Prefer stable attributes such as data-testid, accessible roles, or other selectors that do not change with layout. A selector matching multiple elements is ambiguous for a screenshot; narrow it with .first(), .nth(index), or a more specific locator, and verify that it identifies the intended node.

Make the scroll step explicit

When reviewing or debugging the script, separate the scroll request from the capture:

const target = page.locator('[data-testid="report-card"]');
await target.scrollIntoViewIfNeeded();
await target.screenshot({ path: 'report-card.png' });

scrollIntoViewIfNeeded() asks Playwright to scroll only when the element is not already sufficiently visible under its IntersectionObserver-based visibility check. It does not promise a particular final alignment such as top, center, or bottom. The subsequent screenshot still performs its normal checks.

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

This two-step form is useful when you need a breakpoint, log statement, or assertion between scrolling and capture:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 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.
await target.scrollIntoViewIfNeeded();
console.log('element is ready for capture');
await expect(target).toBeVisible();
await target.screenshot({ path: 'ready.png' });

If your requirement is “never move the page,” locator screenshots are not documented to support that mode. Instead, reconsider the capture scope, capture an already-visible clone, or save the page state before and after the operation and treat any movement as expected API behavior.

Scrollable containers need separate handling

A selector can match a scrollable panel rather than a simple block. The screenshot then shows the content currently visible inside that panel; it does not automatically stitch every item hidden behind the panel’s own scrollbar.

Capture the panel’s current view

const panel = page.locator('[data-testid="activity-panel"]');
await panel.screenshot({ path: 'activity-current-view.png' });

Move the panel’s internal scroll position first

const panel = page.locator('[data-testid="activity-panel"]');
await panel.evaluate((node) => {
  node.scrollTop = node.scrollHeight;
});
await panel.screenshot({ path: 'activity-bottom.png' });

That example changes the panel itself, not the window. For a reproducible capture, wait for the content you expect after changing the position and confirm the selector still resolves to the same container. If you need all rows, capture each intended state or redesign the test so the content is rendered without an internal scrollbar; a locator screenshot is not a full-page stitcher for nested scrollers.

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

Capture the whole page instead

When the selector is only being used to describe a page section but the deliverable is the entire document, use:

await page.screenshot({ path: 'page.png', fullPage: true });

fullPage: true asks the page API to capture the full scrollable page as if the viewport were tall enough to contain it. It does not clip to a selected element and should not be substituted for locator.screenshot() when you need only one component.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • 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.

Wait for the right state before scrolling

Automatic scrolling does not mean that asynchronous content is ready. Wait for the page state that determines the pixels you want:

await page.goto('https://example.com/dashboard', { waitUntil: 'domcontentloaded' });
await page.locator('[data-testid="report-card"]').waitFor({ state: 'visible' });
await page.locator('[data-testid="report-card"] img').waitFor({ state: 'visible' });
await page.locator('[data-testid="report-card"]').screenshot({ path: 'dashboard-card.png' });
  • Use a locator wait for an element that is inserted after navigation.
  • Wait for a specific loading indicator to disappear when it covers the target.
  • For fonts, images, charts, or animations, add an application-level readiness signal rather than relying only on navigation completion.
  • Disable or pause animations in test CSS when stable pixels matter; scrolling itself does not freeze animation.

Do not assume that networkidle means every visual component is finished. A page can continue rendering from timers, workers, or already-cached resources.

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

Common failures and fixes

“Element is not attached to the DOM”

A detached target was replaced between locating and capturing. Use a locator rather than retaining an old element handle, wait for the component’s final state, and avoid triggering a rerender immediately before the screenshot.

The image contains the wrong part of a panel

The selector probably matched a scrollable container whose internal position was not what you expected. Set scrollTop or interact with that container, wait for its content, then capture again.

The screenshot is clipped to one card, not the page

That is the defined locator behavior. Replace the call with page.screenshot({ fullPage: true }) for a page image, or capture both outputs when you need a component image and page context.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • 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

The selector matches the wrong element or several elements

Inspect the locator count and refine the selector:

const cards = page.locator('[data-testid="report-card"]');
console.log('matches:', await cards.count());
await cards.nth(0).screenshot({ path: 'first-card.png' });

Use an accessible name, a unique test identifier, or a parent-child relationship instead of relying on a generated class name.

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

The page moved even though I did not call scroll

That is expected when the target is outside the visible area: locator.screenshot() scrolls it into view. Playwright’s documented locator screenshot API does not expose a supported switch to suppress that behavior.

The target is visible but capture times out

Actionability checks can wait while an overlay, transition, or continuously changing element prevents a stable action. Close the overlay, wait for the transition to end, or capture a stable test fixture. Also verify that the selector resolves in the same frame or browsing context where it was created.

Reliability and performance considerations

  • Use one locator per intended image. It makes selector changes and failures easier to diagnose than passing around stale element handles.
  • Keep the viewport deterministic. Set the viewport and device scale consistently in CI so line wrapping and element dimensions do not change.
  • Control internal scroll state. A panel’s scroll position is part of the visual input even when the outer page position is correct.
  • Minimize unnecessary full-page captures. A locator screenshot usually requires less image data and less processing when a component is all you need.
  • Expect layout shifts from lazy content. Wait for the content that changes the target’s dimensions before scrolling and capturing.
  • Keep evidence of failures. On a failed assertion, save a page screenshot and relevant HTML or trace so you can distinguish a bad selector from a scroll-state problem.

The official Playwright references establish the API behavior described here; they do not provide an independent benchmark for screenshot speed or a guarantee of a particular final scroll alignment.

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

Or skip the browser setup

ScreenshotNeo provides a website screenshot API when you want a rendered URL without maintaining a Playwright browser process. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. It can also capture a selected element by CSS selector, wait for a selector, use custom JavaScript or CSS, set viewport and device options, and return PNG, JPEG, WebP, or PDF.

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

For a direct request, see the ScreenshotNeo API documentation:

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 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.
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)
r.raise_for_status()
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}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

An MCP server supplies take_screenshot, get_page_info, and capture_pdf tools to Claude, Cursor, and other MCP clients, so AI agents can perform captures directly. Every feature is available on every plan.

Plan Allowance Price
Free 1,000 shots/month $0, no card
Starter 3,000 shots $5
Growth 15,000 shots $15
Pro 60,000 shots $39
Scale 250,000 shots $99
Business 1,000,000 shots $249

Yearly billing gives two months free. If cookie banners, popups, chat widgets, failed loads, or an AI-agent workflow are the reason you are avoiding browser setup, start with 1,000 free screenshots a month and no card; paid plans start at $5 for 3,000 shots.

Practical decision checklist

  1. Need one component? Use locator.screenshot().
  2. Need the scroll operation visible in code? Call scrollIntoViewIfNeeded() first.
  3. Need a panel’s lower items? Set that panel’s internal scroll position before capture.
  4. Need the complete document? Use page.screenshot({ fullPage: true }).
  5. Need URL screenshots without browser orchestration? Use ScreenshotNeo’s API or MCP server.

Frequently Asked Questions

Can I force Playwright to align the element at the top of the viewport?

The documented locator screenshot behavior scrolls the element into view but does not promise top, center, or bottom alignment. If alignment is important, perform your own page or container scroll operation before capturing and verify the resulting state.

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

Does a locator screenshot include content hidden below an element’s CSS overflow?

No. It captures the element’s rendered region and the content currently visible inside a scrollable container. Move the container’s internal scroll position or use a different capture design for hidden content.

Is ElementHandle.screenshot() required for selector screenshots?

No. The locator API is the preferred approach: create a locator with CSS or XPath and call its screenshot method. The ElementHandle screenshot reference is marked discouraged.

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.