question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Selector text-matches not working as expected

See original GitHub issue
const { 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:closed
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jacobmesucommented, Oct 6, 2022

@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.

1reaction
ltsudacommented, Sep 27, 2022

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 the div and :text-matches.. https://playwright.dev/docs/selectors#text-selector

const locator = await page.locator(`div: text-matches("^Vaste activa$", "i")`);
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found