[Question] Selector text-matches not working as expected
See original GitHub issueconst { chromium } = require("playwright");
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.setContent(`
<div class="SpotlightEntry-title">
<span class="SpotlightEntry-char is-highlighted">Vaste</span>
<span class="SpotlightEntry-char"> </span>
<span class="SpotlightEntry-char is-highlighted">activa</span>
</div>
`);
const locator = await page.locator(`div:text-matches("^Vaste activa$", "i")`);
console.log(await locator.innerHTML());
await browser.close();
})();
Why doesn’t this work? I’d expected it to match on the div. But it doesn’t. 😦 I want to match SpotlightEntry-title on the innertext with support for nbsp; exact text matching and case insensitive.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
java - Looking at the ExpectedConditions class, trying to find ...
not (ExpectedConditions.textMatches( By.cssSelector(selector), Pattern.compile(beforeCount))));. It will timeout if it doesnt change, ...
Read more >What Is ExpectedConditions In Selenium (With Examples)
This method of Expected Conditions in Selenium Java checks whether the title of the current page matches with the expected title. It returns ......
Read more >[Question] How to locate parent element with exact child text ...
Hi, I have problem with locating element containg text. ... know I can look for: playwright.locator('div:text-matches("Playwright","gm")'), ...
Read more >Test Object with xpath selector using matches() function never works ...
I expected that both Test Objects success to match the HTML element ... Objects in Katalon Studio with Condition “matches regex” will not...
Read more >How to wait until for "particular text" is present that to using ...
We have simple simple solution for this. Either you can convert your Expected variable and Actual variable to Lowercase or Uppercase before ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@yury-s that works for me, thanks! There are no whitespaces in my vscode code, but it seems to treat an endline like a whitespace.
There might be a better way, but I can’t look at the moment.
Just using the same way you are doing, please see here the
#nav-bar :text-matches("reg?ex", "i")example in the following link. I think in your case, you need to add a space between thedivand:text-matches..https://playwright.dev/docs/selectors#text-selector