selector highlighting all 4 buttons
code for "COVID-19 Resume" element
This selector:
cy.get('.mat-mdc-row[data-canedit="true"]:has(.mat-column-categories>span) .mat-column-actions button[id^=actionMenu]')
highlights all 4 buttons in the far-right column. How can I modify it to where only the buttons in the same row as the "COVID-19-Resume" category get selected.
I tried
.mat-mdc-row[data-canedit="true"]:has(.mat-column-categories>span:contains("COVID")) .mat-column-actions button[id^=actionMenu]
But that showed 0 results.
2
Answers
Have you tried using the
cypress
‘scontains
method to select by the value inside and get the element, then useparent()
to access the row element, finally select the button usingget()
method.To find the row that has "Covid" in the second column, use
td:nth-child(2):contains("Covid")
.To illustrate, here’s a similar test on the Material Angular examples page.
You have more than one Category with "Covid", so I recommend adding
:first
as well,