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

Unable to verify a special character string in Cypress

I have to verify a special character string on a webpage on different elements using Cypress.

Special character string is : T!@$^()-_+, &_-=tt.Ø {y}[a] £ fi

Whenever I try to verify the string I get below assertion error in Cypress:

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

AssertionError Timed out retrying after 4000ms: Expected to find content: 'T!@$^()-+, &-=tt.Ø {y}[a] £ fi' within the element: <label> but never did.

Below is the screenshot:
enter image description here

Below is the code block:

    cy.visit('public/special-character.html')
    
    cy.get('label').contains('T!@$^()-_+, &_-=tt.Ø {y}[a] £ fi');
    cy.get('p').contains('T!@$^()-_+, &_-=tt.Ø {y}[a] £ fi');
   
  })

and also attached a sample HTML page:

<html><head>
<title>Special Character String</title>

<body>
<h3> Below is the special charcter string needs to be verified using Cypress</h3>
<label>T!@$^()-_+, &_-=tt.Ø {y}[a] £ fi</label>
<p>T!@$^()-_+, &_-=tt.Ø {y}[a] £ fi</p>
</body>
</head>
</html>

>Solution :

What do you want to test?

  • If you want to get the element, get already fetches it. So no need for it. Otherwise, if you want to retrieve <label>, you can do your cy.contains at the top
cy.contains('T!@$^()-_+, &_-=tt.Ø {y}[a] £ fi').should('exist'); // return <label>
  • If you want to assert that the text contains the desired text, you can try the following:
cy.get('label').should('have.text','T!@$^()-_+, &_-=tt.Ø {y}[a] £ fi');

EDIT: by the way, in the picture we can identify underscore _, where you don’t have it in your code

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