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 OverflowPlaywright
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.
Videos
15:50
18. Playwright Made CSS Selector Powerful? Pseudo Class | has-text ...
29:41
#7 - Locators (ID, ClassName, Text, CSS Selector, XPath) in ...
10:14
Locator - Has & Has Text | Playwright Tutorial part - 69 - YouTube
10:25
15. Mastering page.locator() in Playwright: has | hasNot | hasText ...
Top answer 1 of 5
12
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}"`) });
}
2 of 5
11
I found an option. Create a regex object and pass that in for hasText.
pageNumberButton(page, table_id, page_number) {
const regexNumber = new RegExp(`^${page_number}$`);
page.locator(`[aria-controls=${table_id}]`, {hasText: regexNumber});
}`
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
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.
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
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
Playwright-user-event
playwright-user-event.org › playwright-tips › playwright-tip-of-the-week-using-internal-has-text-in-locators
Playwright Tip of the Week: Using internal:has-text in Locators
locator('<css-selector> >> internal:has-text=<regex>')
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.
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.
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