microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.41k stars 3.63k forks source link

[BUG] :text() selector documentation issue #12732

Closed dajunhuo closed 2 years ago

dajunhuo commented 2 years ago

Context:

Code Snippet

#nav-bar :text("Home")

Describe the bug

The documentation for text selectors as seen in the URL https://playwright.dev/dotnet/docs/selectors#text-selector only worked for me if I remove the space between the element and the colon e.g.

#nav-bar:text("Home")

Here's an example of what I was trying to select (with text censored) image

pavelfeldman commented 2 years ago

#nav-bar:text("Home") and #nav-bar :text("Home") are two different selectors with different semantics. First is looking for an element nav-bar that has given text, another is looking for nested elements inside navbar that have text.

You would typically say #nav-bar:hasText("Home") instead, or better yet page.locator('#nav-bar', { hasText: 'Home' }).