Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

485
Views
Cypress clock function makes html body invisible

in my cypress tests, I am looking to set the clock to a specific time to have a consistent time frame for every test.

When I call:

cy.visit('/path/to/page');
cy.get('#elementId').click();

All is fine.

However, when I do:

cy.clock(Date.now());
cy.visit('/path/to/page');
cy.get('#elementId').click();

I get the following error:

This element `<button with Id i want to click>` is not visible 
because its parent `<body>` has CSS property: `display: none`

This also happens when I pass no arguments to cy.clock(). Why is cy.clock() setting the body of this page to invisible? And how do I avoid this?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

The cy.clock() command overwrites and freezes the javascript functions relating to timers - setTimeout, setInterval as well as the Date objects.

It looks like your app makes use of setTimeout during loading and some initial javascript is not completed.

Try adding a cy.tick() to the command sequence

cy.clock(Date.now());
cy.visit('/path/to/page');
cy.tick(1000);                 // try longer and shorter timings
cy.get('#elementId').click()
about 4 years ago · Santiago Trujillo Report

0

How about you provide a custom out for the element to be visible first and then click().

cy.get('#elementId', {timeout: 6000}).should('be.visible').click()

Or, You can also use {force: true} in case you want to click a hidden element.

cy.get('#elementId', {timeout: 6000}).should('be.visible').click({force: true})
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!