Search code examples
node.jsplaywright

Playwright - how to print element to HTML (.outerHTML)?


I'm using Playwright with node.js. I've found an element with page.$$, how do I save its outer HTML to string?


Solution

  • 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.