Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
ElementHandle
Caution
This API is a work in progress. Some of the following functionalities might behave unexpectedly.
Examples
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();
}
}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();
}
}

