docs: small clarifications to hasText and has-text (#13298)

This commit is contained in:
Dmitry Gozman 2022-04-04 13:18:03 -07:00 committed by GitHub
parent 8a6b640fca
commit 4e1fb1728f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 11 deletions

View File

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

View File

@ -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.
```js
await page.locator('button', { hasText: 'Click me' }).click();
@ -494,6 +494,8 @@ Locators support an option to only select elements that have some text somewhere
await page.Locator("button", new PageLocatorOptions { HasText = "Click me" }).ClickAsync();
```
You can also pass a regular expression.
### Filter by another locator
Locators support an option to only select elements that have a descendant matching antoher locator.

View File

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