Thursday, May 16, 2024

Cypress Not Finding Dynamic Text

I ran into a situation today where Cypress was not finding some text that was added dynamically to the DOM after page load using jQuery. Here is my initial attempt:
it('displays the total amount', () => {
    cy.get('#total-amount').contains('$100.00');
});
And here is what finally worked:
it('displays the total amount', () => {
    cy.get('#total-amount').then(($elem) => {
        assert($elem.text() === '$100.00');
    });
});
 
Blogger Templates