Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

How to Scroll to an Element With Puppeteer Locators

Use Locator.scroll() for deliberate vertical or horizontal movement; ordinary locator actions already bring off-screen targets into view by default.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use await page.locator(selector).scroll({ scrollTop, scrollLeft }) to explicitly scroll a located element with Puppeteer. If your goal is simply to click an off-screen target, you usually do not need a separate scroll call: locator actions ensure the target is in the viewport by default.

Explicitly scroll a located element

Call scroll() on the locator and supply the vertical and/or horizontal offset you want. Puppeteer’s guide says this operation uses mouse wheel events; the options are documented in the LocatorScrollOptions reference.

As an Amazon Associate I earn from qualifying purchases.

await page.locator('#results').scroll({
  scrollTop: 240,
  scrollLeft: 0,
});

Replace #results with a selector for the element whose scrollable area you want to move. Use positive or negative offsets as appropriate to the page’s current position; the example is not a request to scroll the page by an absolute coordinate.

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

Complete runnable example

This Node.js example launches Chromium, loads a page containing an overflowing element, scrolls that element, and closes the browser:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({ headless: true });
  try {
    const page = await browser.newPage();
    await page.setContent(`
      <div id="results" style="height: 120px; width: 260px; overflow: auto">
        <div style="height: 600px; width: 500px">Scrollable content</div>
      </div>
    `);

    await page.locator('#results').scroll({
      scrollTop: 240,
      scrollLeft: 40,
    });
  } finally {
    await browser.close();
  }
})();

Install Puppeteer in the project before running the example, for instance with npm install puppeteer. The official page interactions guide shows the locator scroll pattern.

When a locator action already scrolls for you

Locator actions automatically ensure that their target is in the viewport by default. So for an off-screen button you intend to click, this is ordinarily sufficient:

await page.locator('button.submit').click();

Locators are Puppeteer’s recommended way to select and interact with page elements. Their actions retry when the element is not ready and check action preconditions, including visibility, viewport presence, and a stable bounding box over consecutive animation frames, as described in the page interactions guide.

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

This automatic viewport behavior is a precondition for an action, not a substitute for choosing a particular scroll offset. Use .scroll() when you need to move a scrollable region deliberately.

Disable automatic viewport handling for an action

setEnsureElementIsInTheViewport(false) returns a cloned locator configured not to perform the automatic viewport check/scroll for its action:

const locator = page
  .locator('button.submit')
  .setEnsureElementIsInTheViewport(false);

await locator.click();

The setting defaults to true. Disabling it does not scroll anything; call scroll() separately if explicit movement is still needed. See the method reference.

Choose a selector that identifies the intended element

page.locator(selector) accepts CSS selectors and Puppeteer selector syntax. The API reference documents text, accessibility role and name, XPath, and selector combinations that can cross shadow roots; consult Page.locator() for the supported syntax.

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.

Prefer a selector that uniquely identifies the scrollable element. If a broad selector matches multiple elements or identifies a child rather than the container that actually scrolls, you may move the wrong region or see no useful movement. For dynamic pages, allow the target to become available before acting; locator operations retry when the element is not ready.

How the three scrolling-related operations differ

Operation What it does Use it when
Locator.scroll({ scrollTop, scrollLeft }) Scrolls the located element using mouse wheel events and the requested offsets. You need explicit movement of the locator’s scrollable area.
Default locator action behavior Ensures the action target is in the viewport before the action, by default. You want to click or interact with an off-screen target and do not need a chosen scroll offset.
ElementHandle.scrollIntoView() Explicitly brings an already-held element handle into view, using the automation protocol client or element.scrollIntoView(). Your code already uses an ElementHandle and needs an into-view operation rather than locator-based interaction.

The lower-level alternative is documented at ElementHandle.scrollIntoView(). These operations have different purposes; do not treat explicit offset scrolling and bringing a target into view as interchangeable.

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

Troubleshooting

The scroll call runs but the page appears unchanged

  • Check whether the locator identifies the scrollable container, rather than a non-scrollable child or a different matching element.
  • Confirm the target has content that can scroll in the requested direction. An element with no overflow has nowhere to move.
  • Remember that scrollTop and scrollLeft are offsets for the wheel-based scroll operation, not absolute page coordinates.

A click works without an explicit scroll call

This is expected: locator actions ensure the target is in the viewport by default. Keep the explicit scroll() call only when you need deliberate scrolling beyond that action precondition.

The target is not ready or the action does not proceed

Locators retry when an element is not ready, and actions check readiness conditions such as visibility and a stable bounding box. Verify that the selector matches the intended element and that the page has reached the state in which it should be actionable; the behavior is described in the official guide.

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

An action no longer performs the expected automatic viewport behavior

Check whether the locator was configured with setEnsureElementIsInTheViewport(false). That option disables the automatic viewport handling for the cloned locator; it does not perform explicit scrolling.

Or skip the browser setup

If your goal is to capture a webpage rather than interact with it in a browser session, ScreenshotNeo provides a website screenshot API and MCP server. One GET request can return a PNG, JPEG, WebP, or PDF. Its capture flow accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; each of those steps can be turned off.

For a WebP screenshot, put your API key in place of YOUR_API_KEY:

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

See the ScreenshotNeo documentation for request options. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers identify the page verdict and whether the request was billed. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

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

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Can Puppeteer scroll horizontally with a locator?

Yes. Pass a horizontal offset with scrollLeft to Locator.scroll().

Does setEnsureElementIsInTheViewport(false) disable Locator.scroll()?

No. It configures the cloned locator’s automatic viewport behavior for actions; explicit scroll() remains a separate operation.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.