Categories
JavaScript Answers

How to find by text content with Cypress and JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *