how do I find an element by using should('have.tex...
# i-need-help
s
I have managed to almost do what I want with the use of: cy.get('ul').then( () => { cy.get('div').contains('test2').click(); }) The problem is that if there is another div in the ul that has the value of 'test22' then there is a high chance that that one will be selected instead. How do I get the right div every time?
g
cy.contains(“ul div”, “test22”)
s
ooh, fast answer! That wont work tho. I want the 'test2' every time without fail. The problem is that it chooses the first div that contains 'test2' (which sometimes is 'test22')
e
cy.contains
allows for regex so I would just use that for an exact match Maybe something like?
.contains(/^test2$/)
s
aah! Lovely! Thanks a lot for the help! I knew there was an easy fix:)