I wrote this code to click on the first option of a dropdown and ran it in Cypress
it('Choosing tag', () => {
cy.get('[data-appearance="textfield"]').eq(1).click();
cy.get('[role="option"]').eq(0).as('option').should('be.visible');
cy.get('@option').then(($option) => {
cy.wrap($option).click();
});
});
But on the cy.click phase I got this error
Timed out retrying after 4050ms: cy.click() failed because the page updated while this command was executing. Cypress tried to locate elements based on this query:
<button.ng-star-inserted>
We initially found matching element(s), but while waiting for them to become actionable, they disappeared from the page. Common situations why this happens: Your JS framework re-rendered asynchronously Your app code reacted to an event firing and removed the element
You can typically solve this by breaking up a chain. For example, rewrite:
cy.get('button').click().click() to cy.get('button').as('btn').click() cy.get('@btn').click()
As you can see in my code, I followed recommendations from the error text but it didn't help. When I visit the page as a user, the required element is clickable.
I hope there are ways to solve this. Thank you.
To stop the test waiting for actionability, you can add the {force:true}
option.
This means that you will be using the old version of the button, but that may be the quickest way around your problem.
There is no need to then()
and wrap()
, it does nothing.
cy.get('[data-appearance="textfield"]').eq(1).click();
cy.get('[role="option"]').eq(0).as('option').should('be.visible');
cy.get('@option').click({force:true})
In a real-world test you will look for
cy.contains(some-page-text)
)cy.intercept('some-api-response')
)to be sure the page is stable before clicking the button.
Since there is no info about your page, I can't give you a specific answer about that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With