I'm using Playwright with node.js. I've found an element with page.$$, how do I save its outer HTML to string?
I'm using Playwright with node.js. I've found an element with page.$$, how do I save its outer HTML to string?
If you have more element handles you got using page.$$() and you want to get an outer html of each, this would be a way:
const outerHtmls = await page.$$eval('.myElement', el => el.outerHtml);
More information about page.$$eval() could be found here.
Playwright doesn't have an outerHTML() function. It sounds like you already have an ElementHandle. If so, try this!
async function outerHtml(elem) {
if(!elem) {
return undefined;
}
return await elem.evaluate(elem => elem.outerHTML);
}
async outerHtml(elem: ElementHandle) {
if(!elem) {
return undefined;
}
//@ts-ignore
return await elem.evaluate(elem => elem.outerHTML);
}