Here is the HTML code I am working with:
<div class="main">
<div class="box">
<div class="cell">checkbox</div>
<div class="cell"></div>
<div class="cell">
<a>link1</a>
</div>
<div class="cell">type</div>
<div class="cell">description</div>
</div>
<div class="box"> //i want to click this element
<div class="cell">checkbox</div>
<div class="cell"></div>
<div class="cell">
<a>link2</a>
</div>
<div class="cell">type1</div>
<div class="cell">description1</div>
</div>
<div class="box">
<div class="cell">checkbox</div>
<div class="cell"></div>
<div class="cell">
<a>link3</a>
</div>
<div class="cell">type2</div>
<div class="cell">description2</div>
</div>
</div>
I want to specifically click on the box
div that contains the link with text <a>link2</a>
.
I attempted to achieve this with the following code:
cy.get(`.main>div`).contains('link2').click();
However, this clicks directly on the link element itself rather than the surrounding div
. Is there a way to target and click on the desired div
containing the link instead?
If you have any advice or solutions for this issue, I would greatly appreciate it. Thank you!