Cypress Wait Until Element Visible

Profile picture for user arilio666

In cypress, we can see if an element is visible or not using the should('be.visible') assertion. Cypress has the best feature of internally retrying commands and doesn't need any wait to ensure the element is visible before verifying.

Table of Contents

  1. Syntax
  2. Example
  3. Wait Until Element is not Visible

Syntax

cy.get(selector).should('be.visible');

Example

Cypress automatically waits for an element and the time is around 4 seconds.  You can also mention timeout in command.

cy.get('.class', { timeout: 12000 }).should('be.visible')

Doing this will make the default wait time for all commands 12 seconds. If there is a need to increase default timeout can be passed inside e2e present in cypress.config.js.

Cypress Wait Until Element is Visible

Wait Until Element is not Visible

To Verify element is not visible use

cy.get('.element').should('not.be.visible')