Want to automate:
My Code:
cy.get('[role=presentation]') cy.get('[role=row]').find('td')
.get('[role=gridcell]').eq(9).click().wait(2000)
cy.get('[role=listbox]').get('[role=option]')
cy.contains('[role=option]', 'Numeric').click()
How can I select only "Numeric" from list, if the list contains other values with that text.
CodePudding user response:
You are asking about how to do an exact match to the option "Numeric", so that the option "AlphaNumeric" is excluded from the search.
To do this, change your cy.contains()
command to use a regular expression. This allows the start-of-string
and end-of-string
tokens to be included in the expression, and therefore gives you and exact match.
^
is start-of-string and $
is end-of-string.
// cy.contains('[role=option', 'Numeric') //matches two options
cy.contains('[role=option', /^Numeric$/) //matches one option only