I have a table with a widget name column, followed by other columns with detail about the widgets.
I have a search function on the page to search for the widget that I want by name. When I search for a widget by name, for example, "abc", the rows returned are "abcde", "aabc", "abc".
My problem arises when I attempt to select the row that I want. Cypress .contains()
always returns the first match, but I'd like the exact match.
I can't guarantee what order the rows will be in either. How can I select abc only?
cy.contains(`${widgetName}`)
Yes
cy.contains()
only returns the first element, but you can switch to:contains()
pseudo-selector to return all.See :contains() Selector
I don't know why Cypress hasn't got an option for multiple matches in
cy.contains()
but:contains()
works.Scan all columns
You have flexibility to test all search results values. Here's a general way to scan the rows:
Just the first column
If you just want to verify first column has
abc
, use :nth-child() Selectoror without looping