I’m using Cypress to test a form which has an input of type="submit". When I select the element with
cy.contains('Submit new data')
it works, but when I use a regex
cy.contains(/Submit new data/)
I get error expected to find content: ‘/Save Changes/’.
Can anyone help me, what is the problem with using regex in .contains().
>Solution :
This is a known issue, but has been fixed in the latest release Cypress v10.3.1 (Released 7/19/2022).
Current behavior
<form> <input type="submit" value="Save Changes" /> </form> cy.contains('Save Changes') // OK. yields input[type='submit'] element cy.contains(/Save Changes/) // ERROR. Expected to find content: '/Save Changes/'
If you have an older version of Cypress, please upgrade and try the same test again.