Reputation: 1961
I need to locate an element/ verify presense of an element, based on the Text inside element, using something like:
//div[contains(text(),'<My intended text>')]
As Cypress.io do not support the XPATh yet, then how to locate it using alternate locators.
There seems to be lot of discussions around cssselectors :contains & when tried div:contains('<My intended text>')
it failed to locate the element.
Given the fact that both XPATH & CSSLocators have good performance on modern browsers.
Kindly advise. Thanks
Upvotes: 0
Views: 2500
Reputation: 3741
so you are looking for the parent which holds 'My intended text'?
You can do so by using:
cy.contains('My intended text')
and that's how you selected the element. Now you can use for example .click()
to click on the element which holds 'My intended text'
Upvotes: 1