DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk5 min

How to Wait for Elements to Blink in Cypress Tests

Cypress retries DOM queries and assertions, but a brief visual blink may escape observation. Choose a durable state, request alias, or explicit app signal.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For an element that appears, disappears, or changes after an action, use a retryable Cypress query and assert the DOM state you need. If a request drives the update, wait for its intercepted request and then query the DOM again. A brief visual blink is different: Cypress does not guarantee that a retrying assertion will observe every frame, so test a durable application state or explicit signal instead.

Wait for an element to appear or become visible

Use a DOM query followed by a state assertion. Cypress retries the linked query and assertion until it passes or reaches its timeout; it does not need a fixed sleep for an ordinary DOM update.

As an Amazon Associate I earn from qualifying purchases.

cy.get('[data-testid="status"]', { timeout: 10000 })
  .should('be.visible')

Use a selector and expected state that match your app. The example raises this command’s timeout to 10 seconds; Cypress’s documented default retry timeout is four seconds. A longer timeout gives a slow operation more time, but also delays failure when the state never arrives.

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

For existence rather than visibility, assert the condition you actually care about, such as .should('exist'). An element can exist in the DOM without being visible.

Wait for an element to disappear

To verify a loading indicator goes away, first establish that it appeared, then make a fresh query for its disappearance:

cy.get('[data-testid="loading"]')
  .should('be.visible')

cy.get('[data-testid="loading"]')
  .should('not.exist')

not.exist checks that the element is removed from the DOM. If your app keeps it in the DOM but hides it, use .should('not.be.visible') instead.

Wait for a request-driven update

If a request triggers the state change, register an intercept before the action, wait for its alias, and then query the UI again:

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.
cy.intercept('GET', '/api/status').as('getStatus')
cy.get('[data-testid="refresh"]').click()
cy.wait('@getStatus')
cy.get('[data-testid="status"]')
  .should('contain', 'Ready')

Replace the endpoint, method, selectors, and expected text with those from the application under test. Waiting for the alias synchronizes the test with the request and response; the fresh DOM query checks the resulting UI state.

An assertion chained directly to the interception yielded by cy.wait() is a single attempt. If a property of that interception needs retrying, use a retryable query such as .its() before asserting it.

Can Cypress reliably catch a blink?

Not if “catch” means observing a fleeting visual frame. Cypress retries DOM queries and assertions; it does not promise to sample every frame of an animation or transient blink. A state that exists only briefly may appear and disappear between assertion attempts.

If the blink itself is the behavior under test, make the application expose a meaningful state or event that the test can assert. Otherwise, assert the durable outcome that matters—for example, that a status changed or a loading state completed. The official Cypress documentation explains that on a failed assertion Cypress re-queries the DOM from the top of the linked query chain: Retry-ability in Cypress. It does not document a built-in command that guarantees an animation has finished or that a transient blink was seen.

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

Avoid fixed sleeps and stale elements

Prefer a condition to a fixed delay

cy.wait(1000) waits one second regardless of whether the application is ready sooner or still needs longer. Prefer a DOM assertion or request alias that represents the condition the test actually needs. Increase an individual command’s timeout only when that operation legitimately needs more time; avoid raising the global timeout casually, since failures then take longer.

Re-query after state changes

A passing .should() can lock in the subject for later commands. If an action or re-render replaces the node, a later command may use a detached element. Start a new query chain after the state change, as in the disappearance and network examples above.

Keep retry callbacks safe

Cypress may execute a .should() callback repeatedly while retrying. Keep assertions in that callback safe to repeat; do not put side effects there.

Know what click retries

Cypress click commands retry their actionability checks until the target can be acted on, but the click itself is attempted once. If the click triggers a request, set up cy.intercept() before clicking so the test does not miss the request.

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

Choose the synchronization point that matches the behavior

What the test needs to observe Use Important limitation
Element appears, becomes visible, changes, or disappears A DOM query with a retryable .should() A transient frame may not last long enough to be observed.
A request completes before the UI is checked cy.intercept(), cy.wait('@alias'), then a fresh DOM query Request completion is not itself proof that the UI reached the expected state.
The blink itself must be detected An explicit application-level state or event signal Cypress does not document a built-in wait that guarantees observation of every animation frame.

Troubleshooting

  • The assertion times out: Check that the selector and expected condition are correct, then determine whether the UI update is slower than the command’s timeout. Raise that command’s timeout only if the longer wait is justified.
  • The element exists but the visibility assertion fails: Existence and visibility are different conditions. Confirm the intended state and assert that state rather than substituting one for the other.
  • The test misses a brief blink: A fleeting visual frame is not a reliable DOM synchronization condition. Expose an application signal or test a durable result.
  • The click appears to miss the request: Register the intercept before the click that triggers it, then wait on the alias.
  • A later command reports a detached element: The application may have replaced the node during a re-render. Begin a new query chain after the action or state change.
  • An assertion on a waited response is flaky: A direct assertion on the interception is a single attempt. Use a retryable query such as .its() when that property needs retries, and separately query the DOM to verify the UI.

Or skip the browser setup

ScreenshotNeo captures a web page as an image or PDF; it is not a replacement for Cypress assertions or a way to synchronize a Cypress test with an element blink. If your separate goal is to capture a page without setting up browser automation, one GET request can return a screenshot. See the ScreenshotNeo documentation.

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

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. It also offers an MCP server for AI agents, and its free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. Learn more at ScreenshotNeo.

Sign up for 1,000 free screenshots a month, with no card.

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.