Skip to content

Commit bb536b6

Browse files
committed
Add new docs page for locator.last
1 parent 8ba1761 commit bb536b6

File tree

1 file changed

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

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: 'last()'
3+
description: 'Browser module: locator.last method'
4+
---
5+
6+
# last()
7+
8+
Returns locator to the last matching element.
9+
10+
### Returns
11+
12+
| Type | Description |
13+
| -------------------------------------------------------------------------------------- | -------------------------------------------------------- |
14+
| [Locator](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/) | The last element `Locator` associated with the selector. |
15+
16+
### Example
17+
18+
{{< code >}}
19+
20+
```javascript
21+
import { expect } from 'https://jslib.k6.io/k6-testing/0.4.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');
40+
41+
await expect(await page.locator('p').last()).toContainText('Contribute to QuickPizza');
42+
43+
await page.close();
44+
}
45+
```
46+
47+
{{< /code >}}

0 commit comments

Comments
 (0)