asElement()
返回 null
或对象句柄本身,前提是对象句柄是 ElementHandle 的实例。
返回值
类型 | 描述 |
---|---|
ElementHandle | null | 如果可用,则为 ElementHandle。 |
示例
import { browser } from 'k6/browser';
export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const page = await browser.newPage();
try {
await page.goto('https://test.k6.io/');
const jsHandle = await page.evaluateHandle(() => document.head);
const element = jsHandle.asElement();
console.log(await element.innerHTML()); // <main class="page">...
} finally {
await page.close();
}
}