From 348277d09c2ffbae585729a3ad97800529b09a14 Mon Sep 17 00:00:00 2001 From: Michael Rienstra Date: Tue, 31 Aug 2021 17:54:39 -0700 Subject: [PATCH] docs: expand "Strictness" examples (#8520) --- docs/src/api/class-locator.md | 20 ++++++++++++++++++-- types/types.d.ts | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/src/api/class-locator.md b/docs/src/api/class-locator.md index e6c94970fa..1ac7e78c07 100644 --- a/docs/src/api/class-locator.md +++ b/docs/src/api/class-locator.md @@ -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 diff --git a/types/types.d.ts b/types/types.d.ts index 5b1eacf81e..8f1de02218 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -8345,6 +8345,9 @@ export interface ElementHandle extends JSHandle { * * // 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(); * ``` * */