docs: expand "Strictness" examples (#8520)

This commit is contained in:
Michael Rienstra 2021-08-31 17:54:39 -07:00 committed by GitHub
parent ae3a4f5257
commit 348277d09c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -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
View File

@ -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();
* ```
*
*/