getAttribute(selector, name[, options])
Warning
Use locator-based
locator.getAttribute()
instead.
Returns the element attribute value for the given attribute name.
Returns
Example
import { browser } from 'k6/browser';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const page = await browser.newPage();
await page.goto('https://test.k6.io/browser.php');
const attribute = await page.getAttribute('#text1', 'onfocus');
console.log(attribute); // prints inputTextOnFocus();
}