Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
docs: small clarifications to hasText and has-text (#13298)
Dmitry Gozman4e1fb1728fdd
diff --git a/docs/src/api/params.md b/docs/src/api/params.mdindex 97a1f1da3c..14346d79c9 100644--- a/docs/src/api/params.md+++ b/docs/src/api/params.md@@ -886,7 +886,7 @@ Slows down Playwright operations by the specified amount of milliseconds. Useful## locator-option-has-text- `hasText` <[string]|[RegExp]>-Matches elements containing specified text somewhere inside, possibly in a child or a descendant element.+Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a [string], matching is case-insensitive and searches for a substring.For example, `"Playwright"` matches `<article><div>Playwright</div></article>`.## locator-option-hasdiff --git a/docs/src/selectors.md b/docs/src/selectors.mdindex 93c7838a6d..abb09ad393 100644--- a/docs/src/selectors.md+++ b/docs/src/selectors.md@@ -310,7 +310,7 @@ Text selector has a few variations:await page.Locator("text=/Log\\s*in/i").ClickAsync();```-- `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. For example, `article:has-text("Playwright")` matches `<article><div>Playwright</div></article>`.+- `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. Matching is case-insensitive and searches for a substring. For example, `article:has-text("Playwright")` matches `<article><div>Playwright</div></article>`.Note that `:has-text()` should be used together with other `css` specifiers, otherwise it will match all the elements containing specified text, including the `<body>`.```js@@ -476,7 +476,7 @@ Consider a page with two buttons, first invisible and second visible.### Filter by text-Locators support an option to only select elements that have some text somewhere inside, possibly in a descendant element.+Locators support an option to only select elements that have some text somewhere inside, possibly in a descendant element. Matching is case-insensitive and searches for a substring.```jsawait page.locator('button', { hasText: 'Click me' }).click();@@ -494,6 +494,8 @@ Locators support an option to only select elements that have some text somewhereawait page.Locator("button", new PageLocatorOptions { HasText = "Click me" }).ClickAsync();```+You can also pass a regular expression.+### Filter by another locatorLocators support an option to only select elements that have a descendant matching antoher locator.diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.tsindex 837b8e15c3..8a53bbd039 100644--- a/packages/playwright-core/types/types.d.ts+++ b/packages/playwright-core/types/types.d.ts@@ -2625,8 +2625,9 @@ export interface Page {has?: Locator;/**- * Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. For example,- * `"Playwright"` matches `<article><div>Playwright</div></article>`.+ * Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a+ * [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches+ * `<article><div>Playwright</div></article>`.*/hasText?: string|RegExp;}): Locator;@@ -5443,8 +5444,9 @@ export interface Frame {has?: Locator;/**- * Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. For example,- * `"Playwright"` matches `<article><div>Playwright</div></article>`.+ * Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a+ * [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches+ * `<article><div>Playwright</div></article>`.*/hasText?: string|RegExp;}): Locator;@@ -9405,8 +9407,9 @@ export interface Locator {has?: Locator;/**- * Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. For example,- * `"Playwright"` matches `<article><div>Playwright</div></article>`.+ * Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a+ * [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches+ * `<article><div>Playwright</div></article>`.*/hasText?: string|RegExp;}): Locator;@@ -13879,8 +13882,9 @@ export interface FrameLocator {has?: Locator;/**- * Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. For example,- * `"Playwright"` matches `<article><div>Playwright</div></article>`.+ * Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a+ * [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches+ * `<article><div>Playwright</div></article>`.*/hasText?: string|RegExp;}): Locator;