Skip to content

Commit 4ca180e

Browse files
committed
Update frame.locator to support options parameter
1 parent 3c6511f commit 4ca180e

File tree

1 file changed

+49
-6
lines changed
  • docs/sources/k6/next/javascript-api/k6-browser/frame

1 file changed

+49
-6
lines changed
Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,61 @@
11
---
2-
title: 'locator(selector)'
3-
description: 'Browser module: frame.locator(selector) method'
2+
title: 'locator(selector[, options])'
3+
description: 'Browser module: frame.locator(selector[, options]) method'
44
---
55

6-
# locator(selector)
6+
# locator(selector[, options])
77

88
The method returns an element [Locator](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/). Locators resolve to the element when the action takes place, which means locators can span over navigations where the underlying dom changes.
99

10-
| Parameter | Type | Default | Description |
11-
| --------- | ------ | ------- | --------------------------------------------- |
12-
| selector | string | `''` | A selector to use when resolving DOM element. |
10+
<TableWithNestedRows>
11+
12+
| Parameter | Type | Default | Description |
13+
| ------------------- | ---------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
14+
| selector | string | `''` | A selector to use when resolving DOM element. |
15+
| options | object | `null` | |
16+
| options.hasText | string or RegExp | `null` | Matches only elements that contain the specified text. String or regular expression. Optional. |
17+
| options.hasNotText | string or RegExp | `null` | Matches only elements that do not contain the specified text. String or regular expression. Optional. |
18+
19+
</TableWithNestedRows>
1320

1421
### Returns
1522

1623
| Type | Description |
1724
| -------------------------------------------------------------------------------------- | ------------------------------------------------ |
1825
| [Locator](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/) | The element `Locator` associated with the frame. |
26+
27+
### Example
28+
29+
{{< code >}}
30+
31+
```javascript
32+
import { browser } from 'k6/browser';
33+
34+
export const options = {
35+
scenarios: {
36+
ui: {
37+
executor: 'shared-iterations',
38+
options: {
39+
browser: {
40+
type: 'chromium',
41+
},
42+
},
43+
},
44+
},
45+
};
46+
47+
export default async function () {
48+
const page = await browser.newPage();
49+
50+
await page.goto('https://quickpizza.grafana.com');
51+
52+
// Get frame
53+
const frame = page.frames()[1];
54+
55+
// Create a locator with text filtering options
56+
const submitButton = frame.locator('button', { hasText: 'Pizza, Please!' });
57+
await submitButton.click();
58+
}
59+
```
60+
61+
{{< /code >}}

0 commit comments

Comments
 (0)