|
| 1 | +--- |
| 2 | +title: 'isVisible(selector[, options])' |
| 3 | +excerpt: 'Browser module: frame.isVisible(selector[, options]) method' |
| 4 | +--- |
| 5 | + |
| 6 | +# isVisible(selector[, options]) |
| 7 | + |
| 8 | +{{% admonition type="warning" %}} |
| 9 | + |
| 10 | +Use locator-based [`locator.isVisible([options])`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/locator/isvisible/) instead. |
| 11 | + |
| 12 | +{{% /admonition %}} |
| 13 | + |
| 14 | +Checks if the element is `visible`. |
| 15 | + |
| 16 | +<TableWithNestedRows> |
| 17 | + |
| 18 | +| Parameter | Type | Default | Description | |
| 19 | +| -------------- | ------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 20 | +| selector | string | `''` | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. | |
| 21 | +| options | object | `null` | | |
| 22 | +| options.strict | boolean | `false` | When `true`, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception. | |
| 23 | + |
| 24 | +</TableWithNestedRows> |
| 25 | + |
| 26 | +### Returns |
| 27 | + |
| 28 | +| Type | Description | |
| 29 | +| ---- | ------------------------------------------------- | |
| 30 | +| bool | `true` if the element is `visible`, else `false`. | |
| 31 | + |
| 32 | +### Example |
| 33 | + |
| 34 | +{{< code >}} |
| 35 | + |
| 36 | +```javascript |
| 37 | +import { browser } from 'k6/experimental/browser'; |
| 38 | + |
| 39 | +export const options = { |
| 40 | + scenarios: { |
| 41 | + browser: { |
| 42 | + executor: 'shared-iterations', |
| 43 | + options: { |
| 44 | + browser: { |
| 45 | + type: 'chromium', |
| 46 | + }, |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | +}; |
| 51 | + |
| 52 | +export default async function () { |
| 53 | + const page = browser.newPage(); |
| 54 | + |
| 55 | + await page.goto('https://test.k6.io/browser.php'); |
| 56 | + |
| 57 | + const frames = page.frames(); |
| 58 | + |
| 59 | + if (frames[0].isVisible('#text1')) { |
| 60 | + console.log('element is visible'); |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +{{< /code >}} |
0 commit comments