Skip to content

Commit 0a4def2

Browse files
committed
Add FrameLocator.locator() method documentation
1 parent c2f7b89 commit 0a4def2

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: "FrameLocator"
3+
description: "Browser module: FrameLocator Class"
4+
weight: 09
5+
---
6+
7+
# FrameLocator
8+
9+
FrameLocator represents a way to find element(s) in an iframe. Frames can be nested, and this locator supports selecting a frame element and then working with it.
10+
11+
A FrameLocator can be created with the [locator.contentFrame()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/) method.
12+
13+
| Method | Description |
14+
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
15+
| [locator(selector[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/framelocator/locator) | Returns a new chained `locator` for the given `selector` within the frame. |
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: 'locator(selector[, options])'
3+
description: 'Browser module: frameLocator.locator(selector[, options]) method'
4+
---
5+
6+
# locator(selector[, options])
7+
8+
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.
9+
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>
20+
21+
### Returns
22+
23+
| Type | Description |
24+
| -------------------------------------------------------------------------------------- | ------------------------------------------------ |
25+
| [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 a locator for an iframe element
53+
const frameLocator = page.locator('iframe').contentFrame();
54+
55+
// Create a locator within the frame with text filtering options
56+
const submitButton = frameLocator.locator('button', { hasText: 'Submit Order' });
57+
await submitButton.click();
58+
}
59+
```
60+
61+
{{< /code >}}

0 commit comments

Comments
 (0)