---
title: "ElementHandle | Grafana k6 documentation"
description: "Browser module: ElementHandle Class"
---

# ElementHandle

> Caution
> 
> This API is a work in progress. Some of the following functionalities might behave unexpectedly.

Expand table

| Method                                                                                                                  | Description                                                                                                                                                 |
|-------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [$(selector)](/docs/k6/latest/javascript-api/k6-browser/elementhandle/query/)                                           | Queries the element for the given selector.                                                                                                                 |
| [$$(selector)](/docs/k6/latest/javascript-api/k6-browser/elementhandle/queryall/)                                       | Queries the elements for the given selector.                                                                                                                |
| [boundingBox()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/boundingbox/)                                   | Returns the bounding box of the element.                                                                                                                    |
| [check(\[options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/check/)                                    | Checks the element if it is a `checkbox` or `radio` button.                                                                                                 |
| [click(\[options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/click/)                                    | Clicks on the element.                                                                                                                                      |
| [contentFrame()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/contentframe/)                                 | Returns the [Frame](/docs/k6/latest/javascript-api/k6-browser/frame/) of the element.                                                                       |
| [dblclick(\[options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/dblclick/)                              | Double clicks on the element.                                                                                                                               |
| [dispatchEvent(type\[, eventInit\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/dispatchevent/)            | Dispatches an event to the element.                                                                                                                         |
| [fill(value\[, options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/fill/)                               | Fills the specified value into the element.                                                                                                                 |
| [focus()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/focus/)                                               | Focuses on the element.                                                                                                                                     |
| [getAttribute(name)](/docs/k6/latest/javascript-api/k6-browser/elementhandle/getattribute/)                             | Returns the specified attribute of the element.                                                                                                             |
| [hover(\[options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/hover/)                                    | Hovers over the element.                                                                                                                                    |
| [innerHTML()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/innerhtml/)                                       | Returns the inner HTML of the element.                                                                                                                      |
| [innerText()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/innertext/)                                       | Returns the inner text of the element.                                                                                                                      |
| [inputValue(\[options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/inputvalue/)                          | Returns the value of the input element.                                                                                                                     |
| [isChecked()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/ischecked/)                                       | Checks if the `checkbox` input type is selected.                                                                                                            |
| [isDisabled()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/isdisabled/)                                     | Checks if the element is `disabled`.                                                                                                                        |
| [isEditable()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/iseditable/)                                     | Checks if the element is `editable`.                                                                                                                        |
| [isEnabled()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/isenabled/)                                       | Checks if the element is `enabled`.                                                                                                                         |
| [isHidden()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/ishidden/)                                         | Checks if the element is `hidden`.                                                                                                                          |
| [isVisible()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/isvisible/)                                       | Checks if the element is `visible`.                                                                                                                         |
| [ownerFrame()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/ownerframe/)                                     | Returns the [Frame](/docs/k6/latest/javascript-api/k6-browser/frame/) of the element.                                                                       |
| [press(key\[, options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/press/)                               | Focuses on the element and presses a single key or a combination of keys using the virtual [keyboard](/docs/k6/latest/javascript-api/k6-browser/keyboard/). |
| [screenshot(\[options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/screenshot/)                          | Takes a screenshot of the element.                                                                                                                          |
| [scrollIntoViewIfNeeded(\[options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/scrollintoviewifneeded/)  | Scrolls the element into view if needed.                                                                                                                    |
| [selectOption(values\[, options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/selectoption/)              | Selects the `select` element’s one or more options which match the values.                                                                                  |
| [selectText(\[options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/selecttext/)                          | Selects the text of the element.                                                                                                                            |
| [setChecked(checked\[, options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/setchecked/)                 | Sets the `checkbox` or `radio` input element’s value to the specified checked or unchecked state.                                                           |
| [setInputFiles(file\[, options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/setinputfiles/)              | Sets the file input element’s value to the specified files.                                                                                                 |
| [tap(options)](/docs/k6/latest/javascript-api/k6-browser/elementhandle/tap/)                                            | Taps the element.                                                                                                                                           |
| [textContent()](/docs/k6/latest/javascript-api/k6-browser/elementhandle/textcontent/)                                   | Returns the text content of the element.                                                                                                                    |
| [type(text\[, options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/type/)                                | Focuses on the element and types the specified text into the element using the virtual [keyboard](/docs/k6/latest/javascript-api/k6-browser/keyboard/).     |
| [uncheck(\[options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/uncheck/)                                | Unchecks the element if it is a `checkbox` or `radio` button.                                                                                               |
| [waitForElementState(state\[, options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/waitforelementstate/) | Waits for the element to reach the specified state.                                                                                                         |
| [waitForSelector(selector\[, options\])](/docs/k6/latest/javascript-api/k6-browser/elementhandle/waitforselector/)      | Waits for the element to be present in the DOM and to be visible.                                                                                           |

## Examples

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import { browser } from 'k6/browser';
import { check } from "https://jslib.k6.io/k6-utils/1.5.0/index.js";

export const options = {
  scenarios: {
    browser: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  // Goto front page, find login link and click it
  try {
    await page.goto('https://test.k6.io/');
    const messagesLink = await page.$('a[href="/my_messages.php"]');

    await Promise.all([page.waitForNavigation(), messagesLink.click()]);
    // Enter login credentials and login
    const login = await page.$('input[name="login"]');
    await login.type('admin');
    const password = await page.$('input[name="password"]');
    await password.type('123');

    const submitButton = await page.$('input[type="submit"]');

    await Promise.all([page.waitForNavigation(), submitButton.click()]);

    await check(page, {
      'header': async p => {
        const h2 = await p.$('h2');
        return await h2.textContent() == 'Welcome, admin!';
      },
    });
  } finally {
    await page.close();
  }
}
```

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import { browser } from 'k6/browser';
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';

export const options = {
  scenarios: {
    browser: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    // Inject page content
    await page.setContent(`
          <div class="visible">Hello world</div>
          <div style="display:none" class="hidden"></div>
          <div class="editable" editable>Edit me</div>
          <input type="checkbox" enabled class="enabled">
          <input type="checkbox" disabled class="disabled">
          <input type="checkbox" checked class="checked">
          <input type="checkbox" class="unchecked">
    `);

    // Check state
    await check(page, {
      'is visible': async p => {
        const e = await p.$('.visible');
        return e.isVisible();
      },
      'is hidden': async p => {
        const e = await p.$('.hidden');
        return e.isHidden();
      },
      'is editable': async p => {
        const e = await p.$('.editable');
        return e.isEditable();
      },
      'is enabled': async p => {
        const e = await p.$('.enabled');
        return e.isEnabled();
      },
      'is disabled': async p => {
        const e = await p.$('.disabled');
        return e.isDisabled();
      },
      'is checked': async p => {
        const e = await p.$('.checked');
        return e.isChecked();
      },
      'is unchecked': async p => {
        const e = await p.$('.unchecked');
        return await e.isChecked() === false;
      },
    });
  } finally {
    await page.close();
  }
}
```
