← Back to library
Cypressselectorsadvancedv12+
cy.contains — find element by text
Locate elements by their visible text content — scope to a selector to avoid ambiguous matches.
1it('finds elements by visible text', () => {
2 cy.visit('/pricing');
3
4 // cy.contains(selector, text) scopes the search to a specific element type
5 cy.contains('button', 'Get started for free').click();
6
7 // Without a selector it searches all elements — good for quick assertions
8 cy.contains('Welcome to your dashboard').should('be.visible');
9
10 // Regex — case-insensitive partial match
11 cy.contains(/plan details/i).should('be.visible');
12});#cy.contains#text#visible text#partial match