[Question] How to locate parent element with exact child text without using RegExp?
See original GitHub issueHi, I have problem with locating element containg text. What is important, I don’t want to search for child element, but I would like to find div, which one of the child element contains defined text. Let’s assume I have 2 elements:
<div><label>Playwright</label></div>
<div><label>Playwright is cool</label></div>
I would like to find element div with exact text “Playwright”. When looking for: playwright.locator(‘div >> text=“Playwright”’) -> it found label When looking for: playwright.locator(‘div:has-text(“Playwright”)’) -> it found div, but both 2 elements 😦
I know I can look for: playwright.locator(‘div:text-matches(“Playwright”,“gm”)’), but I would like not to use RegExp (if possible)
Is there any possibility I could search for this element without using RegExp? Or maybe is there a locator allowing me to look for parent? Then I could found <label>Playwright</label>, and based on this find parent(div)?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
Try the following snippet. Note the double quotes in the
text=selector - these insist on the strict match. Learn more in this guide.Closing as per above since the main issue is answered.