https://cypress.io logo
Hi guys, How can I get an element containing an e...
# e2e-testing
b
Hi guys, How can I get an element containing an element with a specific attribute?
Copy code
html
<label data="" class="checkbox">
 <span data-v="" class="checkbox-title-wrapper">
  <input data-v="" is-checked="true" type="checkbox" name="membership" class="sr-input">
  <span data-v="" class="check-icon" data-cypress-el="true"></span><span data-v="" class="fw:bold">Discount </span>
  </span>
 <span data-v="" class=" mt:8-rem fs:14-rem">Some Text
 </span><!----><!---->
</label>
I would want to get the
label
here that contains any element with
name="membership"
I know that I can get it like
cy.get('.checkbox').contains('.checkbox', 'Discount')
but thats only checking the text inside a child element, and yielding the provided parent.