https://cypress.io logo
You have a few ways, but in this situation I would...
# e2e-testing
w
You have a few ways, but in this situation I would see if there's a way to select the label of the question itself, and then target the yes/no options from there. Then if stuff moves around in the page, it doesn't break your test. If that's not ideal in your setup another option is to put a
data-testid
attribute the element you want to select, and use that as your selector. And then there is always
.eq(n)
(https://api.jquery.com/eq/) so you could do
cy.get('.whatever').eq(1)
to get the second matching element. The drawback with that is that if, say, another question is added above, your tests will now be selecting that other option instead of your intended set, which could produce confusing results.