Hello peoplee!!
I’m working on a Cypress test where I need to select a very specific HTML element from a set of similar structures. I need to select the .row
element based on multiple conditions regarding its nested text content.
Here’s the HTML I’m working with:
<div class="row">
<span class="code">001</span>
<span class="ref">002</span>
<label>Some Label</label>
</div>
<div class="row">
<span class="code">002</span>
<span class="ref">002</span>
<label>Another label</label>
</div>
<div class="row">
<span class="code">002</span>
<span class="ref">001</span>
<label>Something</label>
</div>
I’m aiming to select the .row
element where the .code
is 002
AND the .ref
is 001
. I tried using:
cy.get('.row').filter(`span.code:contains("002")span.ref:contains("001")`)
However, this Cypress selector doesn’t seem to work as expected, even when I try it with a single condition.
Could someone provide guidance on the correct approach for combining these types of conditions to select the desired element? Any insights into what I might be missing would be greatly appreciated.