October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Capture a Cypress Screenshot After Scrolling to an Element

Use Cypress .scrollIntoView(), then query the target again before taking an element screenshot. Capture the current viewport or full page when that better fits your test.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Scroll the element into view, then query it again and call .screenshot(). Cypress warns that commands depending on the yielded subject should not be chained after .scrollIntoView(), so the fresh query is important. To capture the visible page area instead of the element alone, use cy.screenshot({ capture: 'viewport' }) after scrolling.

Capture the element after scrolling

Use a selector that identifies the target, scroll it into view, then make a new query before asserting visibility and taking the element screenshot:

As an Amazon Associate I earn from qualifying purchases.

cy.get('[data-testid="target"]')
  .scrollIntoView()

cy.get('[data-testid="target"]')
  .should('be.visible')
  .screenshot('target-after-scroll')

The second cy.get() is deliberate: Cypress documents that it is unsafe to chain further commands that rely on the subject after .scrollIntoView(). The screenshot command can be chained from a command yielding a single DOM element. Cypress scrollIntoView documentation · Cypress screenshot documentation

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

Choose what the screenshot should contain

Only the target element

Call .screenshot() on the queried element as in the example above. Cypress captures the selected element; use the screenshot option padding if you need space around it. The capture option does not apply to element screenshots. See Cypress screenshot options.

#1 Best Overall

The current viewport

Scroll the page to the desired region, then capture the visible application area:

cy.get('[data-testid="target"]').scrollIntoView()
cy.get('[data-testid="target"]').should('be.visible')
cy.screenshot('viewport-after-scroll', { capture: 'viewport' })

This captures the current viewport, not just the element. Cypress’s documentation shows the visibility assertion separately after scrolling. ScrollIntoView API · Screenshot API

The full page or Cypress runner

  • { capture: 'fullPage' } captures the application from top to bottom by scrolling and stitching images. Fixed or sticky elements may appear more than once.
  • { capture: 'runner' } includes the browser viewport and Cypress Command Log. Failure screenshots are coerced to runner capture.

These are distinct from an element screenshot and a current-viewport screenshot; choose based on the output you need. Cypress screenshot API

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
  • 256 GB SSD of storage.
  • Multitasking is easy with 16GB of RAM
  • Equipped with a blazing fast Core i5 2.00 GHz processor.

Adjust scrolling and visibility checks

.scrollIntoView() accepts duration, easing, offset, and timeout. An offset adjusts the target position after scrolling, which can help when a fixed header covers it. For example:

cy.get('[data-testid="target"]').scrollIntoView({ offset: { top: -80, left: 0 } })
cy.get('[data-testid="target"]')
  .should('be.visible')
  .screenshot('target-after-scroll')

The scroll command fires once; it is not itself retried. Assertions added after it are retried until they pass or time out. Cypress snapshots do not accurately show scroll positions, so inspect the actual run or its video when debugging where the page landed. Cypress scrollIntoView API

Understand screenshot timing and saved files

Screenshot capture is asynchronous: the application can change between command issuance and image capture, so the screenshot may not exactly represent the state at the instant the command ran. Cypress describes the screenshot action as taking around 100 ms; that is documentation guidance, not a guaranteed duration or independent benchmark. Cypress screenshot API

Rank #3
15.6 Inch Win 11 Laptop Computer, N4020, 4GB DDR4 RAM, 128GB Storage | LPDDR4 RAM, 180° Lay-Flat, Dual-Band WiFi, Type-C PD Fast Charging, Thin & Lightweight for Students, Home & Office, Gray
  • WINDOWS 11 | STABLE PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 system, this laptop delivers stable performance for everyday computing tasks. It supports web browsing, online learning, document editing, email communication, and basic office work with optimized power efficiency, providing a practical and reliable experience for essential daily use for daily use.
  • 15.6” FHD IPS DISPLAY: Features a 15.6-inch Full HD IPS display with narrow bezels, offering wider viewing angles and clearer image details compared to standard panels. The improved screen-to-body ratio enhances visual experience for study, reading, document work, and video playback, making it suitable for both productivity and entertainment use.
  • 4GB DDR4 + 128GB eMMC STORAGE: Equipped with 4GB DDR4 memory and 128GB eMMC storage for everyday basics such as browsing, documents, email, and online learning platforms. The built-in TF card slot supports storage expansion up to 1TB, giving you more flexibility for files, photos, videos, and daily documents. TF card not included.
  • CONNECTIVITY & PORTS: Includes 1× TF card slot, 2× USB 3.2 Gen1 ports, and 2× full-featured Type-C ports (USB 3.2 Gen1). The Type-C ports support data transfer, charging, and video output, enabling flexible connection with external devices such as monitors, storage, and peripherals for daily work and study use.
  • LIGHTWEIGHT DESIGN | ONLINE COMMUNICATION: Designed with a slim, portable profile, this laptop is easy to carry for school, commuting, and travel. A built-in 1MP front camera supports online classes, video meetings, remote communication, and everyday conferencing. The 3300mAh battery works with the low-power system design to support practical daily use, while thermal optimization helps maintain quieter operation during extended tasks.

Manually captured screenshots are saved by default in cypress/screenshots, with names based on the spec and test; you can provide a screenshot name, and the folder is configurable. Cypress supplies onAfterScreenshot information such as path and dimensions. The after:screenshot Node event runs after the file is written and can inspect or modify screenshot details; it runs in Node, so Cypress cy commands are unavailable there. Screenshot command · after:screenshot event

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

Troubleshoot common problems

  • The screenshot command acts on the wrong or stale subject: do not chain a subject-dependent command after .scrollIntoView(). Run a fresh cy.get(selector) before checking visibility and capturing.
  • The target is obscured by a fixed header: adjust offset in .scrollIntoView(), then re-query and verify visibility.
  • The assertion times out: remember the scroll itself runs once; the subsequent visibility assertion retries. Check that the selector matches the intended element and inspect the actual run or video because Cypress snapshots do not accurately represent scroll positions.
  • A full-page image repeats a header or other fixed content: this can happen because full-page capture scrolls and stitches images. Use an element screenshot or viewport capture if that better matches the intended output.
  • The image differs from the moment the command was issued: capture is asynchronous and the application may change before the image is taken.

Or skip the browser setup:

For a screenshot returned by an API rather than saved by a Cypress test, ScreenshotNeo takes a URL in one GET request and can return PNG, JPEG, WebP, or PDF. Its clean-shot flow accepts cookie or 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 cost nothing, and response headers report the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients.

Example cURL request (replace the example URL and 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 API documentation. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up free for 1,000 screenshots a month, no card required.

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 *

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.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.