Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using Contains with a regex on input[type="submit"]

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/’.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading