mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
docs: small clarifications to hasText and has-text (#13298)
This commit is contained in:
parent
8a6b640fca
commit
4e1fb1728f
@ -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
|
||||
|
@ -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.
|
||||
|
20
packages/playwright-core/types/types.d.ts
vendored
20
packages/playwright-core/types/types.d.ts
vendored
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user