Sometimes, we want to find by text content with Cypress and JavaScript.
In this article, we’ll look at how to find by text content with Cypress and JavaScript.
How to find by text content with Cypress and JavaScript?
To find by text content with Cypress and JavaScript, we use the contains
method.
For instance, we write
cy.get(".YOUR_BUTTON_CLASS").contains("Customer");
to call get
to get the element with class YOUR_BUTTON_CLASS
.
Then we call contains
to find the element in the button that has text 'Customer'
.
Conclusion
To find by text content with Cypress and JavaScript, we use the contains
method.