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.
Use locator.
Use of $$ is discouraged per latest playwright docs.
const tweets = page.locator('.tweet .retweets');
expect(await tweets.evaluate(node => node.outerHTML)).toBe('10 retweets');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With