https://cypress.io logo
Handling .contains when text contains zero-width s...
# i-need-help
p
Hello! I thought I had this solved until it reared its ugly head again recently. Our platform uses zero-width spaces for some of our text. Very barebones example of the HTML: https://gist.github.com/jessica-jorgenson/780e53e3309fa03ee676592e3aa1228f Where I'm attempting to find the choice and grab its label
Copy code
js
cy.get('[class*="spanWithText"]')
            .contains(option) // option could be 501-1000
            .closest('label')
I attempted the examples here: https://glebbahmutov.com/cypress-examples/recipes/non-breaking-space.html#non-breaking-space, besides manually entering the zero-width code since not all choices will have zero-width spaces in our other cases, and would just like to enter what the human sees and without manipulating a large amount of HTML. Our developer used this: https://discord.com/channels/755913899261296641/961325024114008064/1086073596499214367 but the error message doesn't help when it goes wrong, so I was hoping to find something more Cypress-y to handle this, especially since I need to chain commands after finding the correct option. Does anyone know how I could go about this? Thanks!