Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Using Regular expressions inside the cy.contains()

Category: Cypress

Cypress allows the use of regular expressions inside contains() function.
As seen in the below example, you can search for the element containing text that starts with b and has one or more word characters (numbers, alphabets, and _)

cy.contains(/^b\w+/)

To ignore the Case Sensitivity while using regular expressions inside contains() function, use { matchCase: false }

cy.get(‘div’).contains(‘capital sentence’, { matchCase: false })

Leave a Reply

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