In my Cypress script, I am looking to click on an element within a div that has the name "name1", description "description1", and title "title1".
Below is the HTML structure:
<div data-testid="table-body" role="rowgroup">
<div role="row" data-testid="table-row-0">
<div role="cell">
<input data-testid="table-row-checkbox"/>
</div>
<div data-testid="table-cell-row-0-column-name">
<button data-testid="expand-row"></button>
<a class="subtle-link">name1</a>
</div>
<div data-testid="table-cell-row-0-column-description">
description1
</div>
<div data-testid="table-cell-row-0-column-isIcon">
<div>
<svg>
<title>title2</title>
</svg>
</div>
</div>
</div>
<div role="row" data-testid="table-row-1">
<div role="cell">
<input data-testid="table-row-1-checkbox"/>
</div>
<div data-testid="table-cell-row-1-column-name">
<button data-testid="expand-row"></button>
<a class="subtle-link">name1</a> //i want to click this element
</div>
<div data-testid="table-cell-row-column-description">
description1
</div>
<div data-testid="table-cell-row-column-isIcon">
<div>
<svg>
<title>title1</title>
</svg>
</div>
</div>
</div>
<div role="row" data-testid="table-row-2">
<div role="cell">
<input data-testid="table-row-checkbox"/>
</div>
<div data-testid="table-cell-row-2-column-name">
<button data-testid="expand-row"></button>
<a class="subtle-link">name2</a>
</div>
<div data-testid="table-cell-row-1-column-description">
description2
</div>
<div data-testid="table-cell-row-0-column-isIcon">
<div>
<svg>
<title>title1</title>
</svg>
</div>
</div>
</div>
</div>
From the above DOM, there are two divs with the name "name1" and description "description1", but the titles are "title1" and "title2".
I attempted the following approach:
cy.get('div[role="row"]')
.find('div', 'name1')
.contains('svg', 'title1')
.parent()
.click();
However, this selects the first element with the name "name1" even though the title is "title2".