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
|
## locator-option-has-text
|
||||||
- `hasText` <[string]|[RegExp]>
|
- `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>`.
|
For example, `"Playwright"` matches `<article><div>Playwright</div></article>`.
|
||||||
|
|
||||||
## locator-option-has
|
## locator-option-has
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,7 @@ Text selector has a few variations:
|
||||||
await page.Locator("text=/Log\\s*in/i").ClickAsync();
|
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>`.
|
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
|
```js
|
||||||
|
|
@ -476,7 +476,7 @@ Consider a page with two buttons, first invisible and second visible.
|
||||||
|
|
||||||
### Filter by text
|
### 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
|
```js
|
||||||
await page.locator('button', { hasText: 'Click me' }).click();
|
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();
|
await page.Locator("button", new PageLocatorOptions { HasText = "Click me" }).ClickAsync();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also pass a regular expression.
|
||||||
|
|
||||||
### Filter by another locator
|
### Filter by another locator
|
||||||
|
|
||||||
Locators support an option to only select elements that have a descendant matching antoher 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;
|
has?: Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. For example,
|
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||||
* `"Playwright"` matches `<article><div>Playwright</div></article>`.
|
* [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches
|
||||||
|
* `<article><div>Playwright</div></article>`.
|
||||||
*/
|
*/
|
||||||
hasText?: string|RegExp;
|
hasText?: string|RegExp;
|
||||||
}): Locator;
|
}): Locator;
|
||||||
|
|
@ -5443,8 +5444,9 @@ export interface Frame {
|
||||||
has?: Locator;
|
has?: Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. For example,
|
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||||
* `"Playwright"` matches `<article><div>Playwright</div></article>`.
|
* [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches
|
||||||
|
* `<article><div>Playwright</div></article>`.
|
||||||
*/
|
*/
|
||||||
hasText?: string|RegExp;
|
hasText?: string|RegExp;
|
||||||
}): Locator;
|
}): Locator;
|
||||||
|
|
@ -9405,8 +9407,9 @@ export interface Locator {
|
||||||
has?: Locator;
|
has?: Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. For example,
|
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||||
* `"Playwright"` matches `<article><div>Playwright</div></article>`.
|
* [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches
|
||||||
|
* `<article><div>Playwright</div></article>`.
|
||||||
*/
|
*/
|
||||||
hasText?: string|RegExp;
|
hasText?: string|RegExp;
|
||||||
}): Locator;
|
}): Locator;
|
||||||
|
|
@ -13879,8 +13882,9 @@ export interface FrameLocator {
|
||||||
has?: Locator;
|
has?: Locator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. For example,
|
* Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a
|
||||||
* `"Playwright"` matches `<article><div>Playwright</div></article>`.
|
* [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches
|
||||||
|
* `<article><div>Playwright</div></article>`.
|
||||||
*/
|
*/
|
||||||
hasText?: string|RegExp;
|
hasText?: string|RegExp;
|
||||||
}): Locator;
|
}): Locator;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue