text body can be escaped with single or double quotes to search for a text node with exact content

    pageNumberButton(page, table_id, page_number) {
       page.locator(`[aria-controls=${table_id}]`)
           .filter({ has: page.locator(`text="${page_number}"`) });
    }
Answer from mackxu on Stack Overflow
🌐
Playwright
playwright.dev › locators
Locators | Playwright
Find an element by the text it contains.
🌐
Playwright
playwright.dev › other locators
Other locators | Playwright
For example, css=article >> text=Hello captures the element with the text Hello, and *css=article >> text=Hello (note the *) captures the article element that contains some element with the text Hello.
🌐
BrowserStack
browserstack.com › home › guide › playwright selectors: types
Playwright Selectors: Types and Best Practices (2026) | BrowserStack
December 26, 2025 - Playwright selectors are mechanisms used to locate and interact with elements on a web page, allowing tests to target elements based on attributes, text, roles, or accessibility properties.
🌐
Playwright
playwright.bootcss.com › python › docs › selectors
Element selectors | Playwright
Selector string starting and ending with a quote (either " or ') is assumed to be a text selector. For example, Playwright converts '"Login"' to 'text="Login"' internally. Playwright augments standard CSS selectors in two ways:
🌐
ScrapeOps
scrapeops.io › home › playwright web scraping playbook › nodejs playwright find elements css selectors
Playwright Guide - How To Find Elements by CSS Selector | ScrapeOps
April 15, 2024 - In this guide, we're going to learn how to find elements using their CSS selector. ... Then check out ScrapeOps, the complete toolkit for web scraping. ... const playwright = require("playwright"); async function main() { //open a browser const browser = await playwright.chromium.launch(); //open a new page const page = await browser.newPage(); //navigate to the site await page.goto("https://quotes.toscrape.com"); //find the first h1 element const h1 = page.locator("h1").first(); const h1Text = await h1.textContent(); console.log(`H1 element: ${h1Text}`); //find all elements with the class "qu
🌐
BugBug
bugbug.io › blog › testing frameworks
Ultimate Guide to Selectors: Playwright Selectors
August 5, 2025 - Playwright's CSS selectors work like regular CSS but are enhanced for automation. XPath Selectors: Useful for complex DOM structures, XPath selectors can navigate and find elements based on their XML path.
🌐
Playwright
cuketest.com › selectors
Selectors | Playwright
article:has-text("Playwright") - the :has-text() pseudo-class can be used inside a css selector. It matches any element containing specified text somewhere inside, possibly in a child or a descendant element.
Find elsewhere
🌐
GitHub
github.com › microsoft › playwright › issues › 11673
[Feature]: css selector pseudoclass that works like `innerText` · Issue #11673 · microsoft/playwright
January 27, 2022 - re-raising #7978 Feature request the current pseudoclasses for matching text, from my understanding, do the following: :has-text - matches every node which contains the specified text :text - match...
Author   DetachHead
🌐
DEV Community
dev.to › zt4ff_1 › playwright-tutorial-for-beginners-4-selectors-and-locators-1l41
Playwright Tutorial for Beginners 4 - Selectors and Locators - DEV Community
April 16, 2023 - wrap the text single or double quotes to make playwright match the exact text. For instance, You can make use of a JavaScript-like regex wrapped in / symbol. For instance: :has-text pseudo-class matches an element that contains specified text ...
🌐
GitHub
github.com › microsoft › playwright › issues › 6326
[Feature Request] Text Selector like :has-text("") but Strict & Case Sensitive > :has-text-is("") · Issue #6326 · microsoft/playwright
April 26, 2021 - Using await page.click('articl... things · There is a possibility currently using the old way of selectors *css=article >> text="Playwright ......
Author   garciallorente-fer
🌐
BugBug
bugbug.io › blog › testing frameworks
Playwright Locators - Comprehensive Guide
November 7, 2025 - ... Playwright supports a variety ... main types include: CSS selectors in Playwright are a cornerstone for selecting elements in the browser efficiently and effectively....
🌐
GitHub
github.com › microsoft › playwright › issues › 2280
[Question] How to query element by containing text · Issue #2280 · microsoft/playwright
May 18, 2020 - Is there a way similar to cssContainingText in protractor. I have to query a element by its text content. I have to get the element which contains the text 'START' among the other three.
Published   May 18, 2020
Author   Bharath-Kumar-S
🌐
Playwright
playwright.dev › other locators
Other locators | Playwright Python
For example, css=article >> text=Hello captures the element with the text Hello, and *css=article >> text=Hello (note the *) captures the article element that contains some element with the text Hello.
🌐
Playwright
playwright.dev › selectors
Selectors | Playwright
Name that is used in selectors as a prefix, e.g. {name: 'foo'} enables foo=myselectorbody selectors. May only contain [a-zA-Z0-9_] characters.
🌐
QA Wiki
ray.run › rayrun › questions › what is the method to verify if a specific string is present in an h1 element using playwright?
What is the method to verify if a specific string is present in an h1 element using Playwright?
We'll use the page.locator() method ... our h1 element. Let's say our h1 element has an id of "title". Here's how you can locate it: const titleElement = await page.locator('#title'); Next, we'll get the text content of the h1 element using the locator.textContent() method...
🌐
Playwright
playwright.dev › other locators
Other locators | Playwright Java
For example, css=article >> text=Hello captures the element with the text Hello, and *css=article >> text=Hello (note the *) captures the article element that contains some element with the text Hello.
🌐
ScrapingBee
scrapingbee.com › webscraping-questions › playwright › how-to-find-elements-by-css-selectors-in-playwright
How to find elements by CSS selectors in Playwright? | ScrapingBee
from playwright import sync_playwright with sync_playwright() as p: browser = p.chromium.launch(headless=False) page = browser.new_page() page.goto("https://scrapingbee.com") # Extract the title using CSS selector and print it title = page.locator('css=title') print(title.text_content())
🌐
egghead.io
egghead.io › lessons › playwright-playwright-selectors
Playwright Selectors | egghead.io
For this particular example, we can also write the same thing, but this time with CSS= as a prefix for the selector. [1:15] In addition to the CSS engine, the other engine that you will use quite commonly is the text engine. This particular example will match any element that contains the case insensitive string submit. Playwright also allows you to change different selectors using the double arrow.
Published   March 8, 2022