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.

Short answer: Playwright’s locator.screenshot() automatically scrolls the matched element into view before capturing it. There is no documented option that disables this behavior. Use locator.scrollIntoViewIfNeeded() when you want the scroll step to be explicit, choose a container or page screenshot when your required scope is different, and treat a selector screenshot as an element-clipped image rather than a snapshot of the current viewport.

What Playwright does before a selector screenshot

The locator screenshot API performs actionability checks, scrolls the matched element into view, and then captures it. This is the documented behavior behind the common surprise that a screenshot changes the page’s scroll position. The call below is the normal approach for an element screenshot:

import { test } from '@playwright/test';

test('capture a card', async ({ page }) => {
  await page.goto('https://example.com');
  await page.locator('[data-testid="pricing-card"]').screenshot({
    path: 'pricing-card.png'
  });
});

The screenshot is clipped to the selected element’s size and position. It is not a full-page image and it is not a record of whatever happened to be visible in the viewport before the call. A locator is preferable to the older ElementHandle.screenshot() API, which Playwright marks as discouraged.

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

Can you stop Playwright from scrolling?

Not through a documented locator.screenshot() switch. The API contract includes scrolling the target into view, and the reviewed Playwright documentation does not define an option to suppress that step. Do not rely on an undocumented flag or assume that a CSS selector will be captured while it remains off-screen.

#1 Best Overall
Sale
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
  • Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
  • Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
  • Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
  • Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
  • Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)

If your goal is simply to make the operation visible in the test, separate the scroll request from the capture:

const target = page.locator('#report');
await target.scrollIntoViewIfNeeded();
await target.screenshot({ path: 'report.png' });

scrollIntoViewIfNeeded() asks Playwright to scroll only when the element is not already completely visible according to its IntersectionObserver visibility check. The subsequent screenshot still performs its normal actionability and scroll-into-view behavior. The explicit call improves readability and gives you a clear place to add logging or assertions; it does not turn off the screenshot method’s automatic behavior.

Choose the screenshot scope that matches your goal

API Output scope Scroll semantics Use it when
locator.screenshot() One matched element, clipped to its bounds Automatically scrolls the target into view before capture You need a component, card, form, or other selected element
page.screenshot({ fullPage: true }) The whole scrollable page as a tall image Captures page content rather than a selector-clipped element You need the complete document, not one node

Use the page API for a whole-page result:

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

A full-page screenshot is a different operation, not a way to keep an element screenshot at its original viewport position. Conversely, adding fullPage to a locator screenshot does not change the fact that the locator API captures the selected element.

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

Selectors: CSS, XPath, and locator checks

Playwright’s locator guide documents CSS and XPath selector strings through page.locator(). Prefer a locator that identifies the intended element reliably, then let the screenshot call wait for actionability:

Rank #2
Sale
Logitech G305 Lightspeed Wireless Gaming Mouse - Black
  • The next-generation optical HERO sensor delivers incredible performance and up to 10x the power efficiency over previous generations, with 400 IPS precision and up to 12,000 DPI sensitivity
  • Ultra-fast LIGHTSPEED wireless technology gives you a lag-free gaming experience, delivering incredible responsiveness and reliability with 1 ms report rate for competition-level performance
  • G305 wireless mouse boasts an incredible 250 hours of continuous gameplay on just 1 AA battery; switch to Endurance mode via Logitech G HUB software and extend battery life up to 9 months
  • Wireless does not have to mean heavy, G305 lightweight mouse provides high maneuverability coming in at only 3.4 oz thanks to efficient lightweight mechanical design and ultra-efficient battery usage
  • The durable, compact design with built-in nano receiver storage makes G305 not just a great portable desktop mouse, but also a great laptop travel companion, use with a gaming laptop and play anywhere
const cssTarget = page.locator('main article[data-id="42"]');
await cssTarget.screenshot({ path: 'article-42.png' });

const xpathTarget = page.locator('//main//article[@data-id="42"]');
await xpathTarget.screenshot({ path: 'article-42-xpath.png' });

When a selector is dynamic, first check that it resolves to the element you expect and that the element is attached. A target that is detached during the operation can produce an error. In applications that re-render after navigation or state changes, acquire the locator after the state change and capture it once the relevant content exists.

Scrollable elements and internal scroll position

A selected element can itself be a scrollable container. In that case, the screenshot contains only the content currently scrolled into view inside the container. Scrolling the outer page until the container is visible does not reveal content that is below the container’s own scroll position.

Set the container’s internal position before capturing the container when a particular region matters:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const panel = page.locator('.log-panel');
await panel.scrollIntoViewIfNeeded();
await panel.evaluate((element) => {
  element.scrollTop = element.scrollHeight;
});
await panel.screenshot({ path: 'latest-log-lines.png' });

The screenshot remains clipped to .log-panel; only the portion exposed by its internal scrolling area appears. If you need all of the page’s content rather than the current contents of a scrollable node, use the page-level full-page API instead.

Rank #3
Sale
Logitech M185 Compact Ambidextrous Wireless Mouse with Rubber Grips - Blue
  • Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
  • Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
  • Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
  • Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
  • Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)

Making capture deterministic

Wait for the right state

Locator screenshots wait for actionability checks, but your application may still be rendering data after the element becomes actionable. Wait for a state that represents the content you intend to preserve, then capture:

const chart = page.locator('[data-testid="sales-chart"]');
await chart.waitFor({ state: 'visible' });
await page.locator('[data-testid="chart-status"]')
  .getByText('Loaded')
  .waitFor();
await chart.screenshot({ path: 'sales-chart.png' });

Use selectors tied to meaningful application state rather than an arbitrary delay whenever possible. If an animation changes the element while the screenshot is taken, wait for the application’s settled state before calling the API.

Keep the intended target unambiguous

Use stable attributes such as data-testid or a semantic locator that identifies one component. If the page can contain several matching nodes, narrow the locator to the correct region before the screenshot call. This also makes failures easier to diagnose than a broad selector that happens to match a different element after a redesign.

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

Understand what “in view” means

Playwright’s documentation defines the need to bring the element into view but does not promise a particular final alignment, such as always placing its top edge at the top or center of the viewport. Tests should assert the image or element content they need, not an assumed alignment that the API does not guarantee.

Rank #4
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
  • Computer mouse for easily navigating a computer interface; click, scroll, and more
  • USB-A wired connection; if existing device only supports USB-C, an additional adapter will be required
  • High-definition (1000 dpi) optical tracking ensures responsive cursor control for precise tracking and easy text selection
  • 3 buttons offer effortless fingertip control
  • Plug-and-go ready for instant use

Common failures and fixes

  • The screenshot contains the wrong region. Confirm that the selector matches the intended element, then inspect whether that element is a scrollable container. A container screenshot reflects its current internal scroll position.
  • The page moved unexpectedly. This is normal for a locator screenshot: the method scrolls the target into view. If you need a whole-document image, call page.screenshot({ fullPage: true }) instead.
  • The target disappears or is detached. A detached target can fail during capture. Reacquire the locator after the page’s update, wait for the replacement element, and then take the screenshot.
  • The image shows an old or incomplete state. Wait for a visible application state that indicates the data or component is ready. Actionability alone does not mean asynchronous content has finished rendering.
  • The element is clipped even though the page is long. Element screenshots are intentionally clipped to the selected element. Use a page full-page screenshot for the entire scrollable document.
  • An explicit scroll call appears to do nothing. scrollIntoViewIfNeeded() does not force a move when the element is already completely visible under Playwright’s visibility definition. The following screenshot call still applies its normal checks.

Examples for reusable helpers

A small helper can make the choice explicit throughout a test suite:

async function screenshotSelector(page, selector, path) {
  const target = page.locator(selector);
  await target.scrollIntoViewIfNeeded();
  await target.screenshot({ path });
}

await screenshotSelector(page, '#checkout-summary', 'checkout-summary.png');

For a full page, keep a separate helper so callers cannot confuse the two scopes:

async function screenshotFullPage(page, path) {
  await page.screenshot({ path, fullPage: true });
}

await screenshotFullPage(page, 'checkout-full-page.png');

Separating these functions documents the intended output and prevents a later change from silently replacing an element capture with a page capture.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you only need a clean URL screenshot rather than Playwright’s test-controlled browser state, ScreenshotNeo provides a single HTTP request. Its service accepts the page URL and returns PNG, JPEG, WebP, or PDF; the API documentation is at https://screenshotneo.com/docs/.

Best Value
Sale
Acer Wireless Mouse for Laptop, 2.4GHz Computer Mouse 3 Adjustable 1600 DPI
  • 【Plug and Play for Home/Office/School】The wireless computer mouse features 2.4GHz connectivity, delivering a stable, interference-free connection up to 32ft. Designed for 𝐦𝐞𝐝𝐢𝐮𝐦 𝐭𝐨 𝐥𝐚𝐫𝐠𝐞 𝐬𝐢𝐳𝐞𝐝 𝐡𝐚𝐧𝐝𝐬, it ensures comfortable use all day. Simply plug in the USB-A receiver for instant pairing—no drivers needed. 📌📌 If the mouse isn’t suitable, place the USB receiver in the battery compartment and return both.
  • 【3 Levels Adjustable DPI】This travel USB mouse offers 3 adjustable DPI settings (800, 1200, 1600), allowing you to customize sensitivity for precise design work. Effortlessly switch to match your task and elevate your productivity. 📌 Please remove the film at the bottom of the mouse before use.
  • 【Effortless Browsing】Equipped with forward and backward buttons, this computer mice streamlines your workflow, making it easy to navigate through web pages and files with a simple click. 📌Side button does not work on Mac.
  • 【Visible Indicator Light】 The pc mouse features a visual indicator for DPI levels and low battery alerts. The red light flashes once for 800 DPI, twice for 1200 DPI, and three times for 1600 DPI. When the battery level is below 10%, the light flashes red until the mouse is completely out of power.
  • 【Click to Wake】With smart sleep mode, it saves power by standby after 10 inactive minutes, just 2-3 clicks to wake. This efficient design delivers 3x longer battery life than motion-wake mice. Engineered for durability, its buttons and scroll wheel are tested for 10 million clicks, ensuring long-term reliability and consistent performance.
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}`);

ScreenshotNeo removes cookie-consent banners, newsletter popups, and chat widgets before capture. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and whether the request was billed. You can also use its MCP server so Claude, Cursor, or another MCP client can call take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots per month without a card, and paid plans start at $5 for 3,000 screenshots. Those clean-page features are useful when you do not need a test’s exact locator state or custom browser session.

Create a free ScreenshotNeo account to use the 1,000 monthly screenshots with no card.

Performance, reliability, and cost considerations

A locator screenshot is usually the narrowest capture: Playwright renders the page, brings one node into view, and writes only that node’s image. A full-page capture can be substantially larger because it represents the entire scrollable document. For visual regression suites, capture only the component under test when page context is unnecessary, and use full-page mode when the document itself is the artifact.

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.

Selector screenshots remain tied to the page session: authentication, client-side data, viewport, browser engine, and application timing all affect the result. Make those inputs consistent in tests and wait on application state rather than relying on an arbitrary sleep. For a URL-only workflow, ScreenshotNeo’s verdict and billed headers let you distinguish a clean billed capture from a failed or unbillable response.

Frequently Asked Questions

Does Playwright guarantee that the element ends at the top or center of the viewport?

No. The documented behavior is that the element is scrolled into view; the API documentation does not promise a particular final alignment.

What should I verify before changing a selector?

Verify both the matched node and its own scroll state. A correct selector can still produce an unexpected image when it identifies a scrollable container whose internal position is not the one you intended.

Quick Recap

SaleBestseller No. 1
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
Product carbon footprint: 3.97 kg CO2e; Contoured shape: Gives you more comfort and control
$14.90
SaleBestseller No. 3
Bestseller No. 4
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
Computer mouse for easily navigating a computer interface; click, scroll, and more; 3 buttons offer effortless fingertip control
$9.70

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.