Skip to content

Commit 199f75f

Browse files
committed
Add docs for locator.boundingBox
1 parent 628e64b commit 199f75f

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

docs/sources/k6/next/javascript-api/k6-browser/elementhandle/boundingbox.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ description: 'Browser module: elementHandle.boundingBox method'
55

66
# boundingBox()
77

8+
{{< admonition type="warning" >}}
9+
10+
Use [locator.boundingBox([options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/boundingbox) instead.
11+
12+
{{< /admonition >}}
13+
814
Returns the bounding box of the element. The bounding box is calculated with respect to the position of the [Frame](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/frame) of the current [ElementHandle](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/elementhandle), which is usually the [Page](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page)'s main frame.
915

1016
### Returns

docs/sources/k6/next/javascript-api/k6-browser/locator/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Locator can be created with the [page.locator(selector[, options])](https://graf
1818
| Method | Description |
1919
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
2020
| [all()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/all) | When multiple elements match the selector, returns an array of `locator`. |
21+
| [boundingBox([options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/boundingbox) | Returns the bounding box of the element. |
2122
| [check([options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/check) {{< docs/bwipt id="471" >}} | Select the input checkbox. |
2223
| [clear([options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/clear) | Clears text boxes and input fields of any existing values. |
2324
| [click([options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/click) {{< docs/bwipt id="471" >}} | Mouse click on the chosen element. |
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: 'boundingBox([options])'
3+
description: 'Browser module: locator.boundingBox method'
4+
---
5+
6+
# boundingBox([options])
7+
8+
Returns the bounding box of the element. The bounding box is calculated with respect to the position of the [Frame](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/frame) of the current element, which is usually the [Page](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page)'s main frame.
9+
10+
<TableWithNestedRows>
11+
12+
| Parameter | Type | Default | Description |
13+
| --------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
14+
| options | object | `null` | |
15+
| options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/). |
16+
17+
</TableWithNestedRows>
18+
19+
### Returns
20+
21+
| Type | Description |
22+
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
23+
| `Promise<null \| Rect>` | A Promise that fulfills with the bounding box of the element as a [Rect](#rect). If the element is not visible, the Promise resolves to `null`. |
24+
25+
26+
### Rect
27+
28+
The `Rect` object represents the bounding box of an element.
29+
30+
| Property | Type | Description |
31+
| -------- | -------- | ------------------------------------------ |
32+
| x | `number` | The x-coordinate of the element in pixels. |
33+
| y | `number` | The y-coordinate of the element in pixels. |
34+
| width | `number` | The width of the element in pixels. |
35+
| height | `number` | The height of the element in pixels. |
36+
37+
### Example
38+
39+
{{< code >}}
40+
41+
```javascript
42+
import { browser } from 'k6/browser';
43+
44+
export const options = {
45+
scenarios: {
46+
browser: {
47+
executor: 'shared-iterations',
48+
options: {
49+
browser: {
50+
type: 'chromium',
51+
},
52+
},
53+
},
54+
},
55+
};
56+
57+
export default async function () {
58+
const page = await browser.newPage();
59+
await page.goto('https://test.k6.io/browser.php');
60+
61+
const textbox = page.locator('#text1');
62+
const boundingBox = await textbox.boundingBox();
63+
console.log(`x: ${boundingBox.x}, y: ${boundingBox.y}, width: ${boundingBox.width}, height: ${boundingBox.height}`);
64+
65+
await page.close();
66+
}
67+
```
68+
69+
{{< /code >}}

0 commit comments

Comments
 (0)