mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 05:37:20 +03:00
docs: expand "Strictness" examples (#8520)
This commit is contained in:
parent
ae3a4f5257
commit
348277d09c
@ -107,6 +107,9 @@ await page.locator('button').click();
|
||||
|
||||
// Works because we explicitly tell locator to pick the first element:
|
||||
await page.locator('button').first().click();
|
||||
|
||||
// Works because count knows what to do with multiple matches:
|
||||
await page.locator('button').count();
|
||||
```
|
||||
|
||||
```python async
|
||||
@ -115,6 +118,9 @@ await page.locator('button').click()
|
||||
|
||||
# Works because we explicitly tell locator to pick the first element:
|
||||
await page.locator('button').first.click()
|
||||
|
||||
# Works because count knows what to do with multiple matches:
|
||||
await page.locator('button').count()
|
||||
```
|
||||
|
||||
```python sync
|
||||
@ -123,21 +129,31 @@ page.locator('button').click()
|
||||
|
||||
# Works because we explicitly tell locator to pick the first element:
|
||||
page.locator('button').first.click()
|
||||
|
||||
# Works because count knows what to do with multiple matches:
|
||||
page.locator('button').count()
|
||||
```
|
||||
|
||||
```java
|
||||
// Throws if there are several buttons in DOM:
|
||||
page.locator("button").click();
|
||||
|
||||
// Works because you explicitly tell locator to pick the first element:
|
||||
// Works because we explicitly tell locator to pick the first element:
|
||||
page.locator("button").first().click();
|
||||
|
||||
// Works because count knows what to do with multiple matches:
|
||||
page.locator("button").count();
|
||||
```
|
||||
|
||||
```csharp
|
||||
// Throws if there are several buttons in DOM:
|
||||
await page.Locator("button").ClickAsync();
|
||||
// Works because you explicitly tell locator to pick the first element:
|
||||
|
||||
// Works because we explicitly tell locator to pick the first element:
|
||||
await page.Locator("button").First.ClickAsync();
|
||||
|
||||
// Works because Count knows what to do with multiple matches:
|
||||
await page.Locator("button").CountAsync();
|
||||
```
|
||||
|
||||
## async method: Locator.allInnerTexts
|
||||
|
3
types/types.d.ts
vendored
3
types/types.d.ts
vendored
@ -8345,6 +8345,9 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
|
||||
*
|
||||
* // Works because we explicitly tell locator to pick the first element:
|
||||
* await page.locator('button').first().click();
|
||||
*
|
||||
* // Works because count knows what to do with multiple matches:
|
||||
* await page.locator('button').count();
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user