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:
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 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,
getalready fetches it. So no need for it. Otherwise, if you want to retrieve<label>, you can do yourcy.containsat 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
