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>
2
Answers
What do you want to test?
get
already fetches it. So no need for it. Otherwise, if you want to retrieve<label>
, you can do yourcy.contains
at the topThis looks like a bug.
The part of the text
=tt.Ø {y}[a]
is causing it to fail. Looks like it’s evaluating to a function declaration.If you try that part of the text in isolation, it also fails
but one char less either end passes
Splitting the string and using
.contains()
on each section will also pass