Skip to content

Commit 36be6c1

Browse files
committed
Add a new locator.count api docs page
1 parent 94f057c commit 36be6c1

File tree

1 file changed

+56
-0
lines changed
  • docs/sources/k6/next/javascript-api/k6-browser/locator

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: 'count()'
3+
description: 'Browser module: locator.count method'
4+
---
5+
6+
# count()
7+
8+
Returns the number of elements matching the selector. This does not wait for actionability checks (whether the matching elements are `visible`, `stable`, and `enabled`). If the return value from `count` doesn't match the expected count, then you should manually retry the API call.
9+
10+
### Returns
11+
12+
| Type | Description |
13+
| ----------------- | --------------------------------------------------------------------------- |
14+
| `Promise<number>` | A promise which resolves with the number of elements matching the selector. |
15+
16+
### Example
17+
18+
{{< code >}}
19+
20+
```javascript
21+
import { expect } from 'https://jslib.k6.io/k6-testing/0.2.0/index.js';
22+
import { browser } from 'k6/browser';
23+
24+
export const options = {
25+
scenarios: {
26+
ui: {
27+
executor: 'shared-iterations',
28+
options: {
29+
browser: {
30+
type: 'chromium',
31+
},
32+
},
33+
},
34+
},
35+
};
36+
37+
export default async function () {
38+
const page = await browser.newPage();
39+
await page.goto('https://quickpizza.grafana.com/login');
40+
41+
const expected = 3;
42+
let match = false;
43+
for (let i = 0; i < 5; i++) {
44+
match = await page.locator('input').count();
45+
if (match == expected) {
46+
break;
47+
}
48+
}
49+
50+
expect(match).toEqual(expected);
51+
52+
await page.close();
53+
}
54+
```
55+
56+
{{< /code >}}

0 commit comments

Comments
 (0)