const puppeteer = require('puppeteer');
const url = process.argv[2]
const selector = process.argv[3]
const browserURL = 'http://127.0.0.1:9222'
;(async () => {
const browser = await puppeteer.connect({browserURL})
const page = await browser.newPage()
await page.goto(url)
const element = await page.$(selector)
console.log(await page.evaluate(el => el.outerHTML, element))
await browser.disconnect()
})();
Input html file.
<html lang="en">
<body>
<div>
<message-content>
ABC
</message-content>
</div>
<message-content>
XYZ
</message-content>
</div>
</body>
<html>
When I run the program with the selector div:has(message-content):last-child
, it can not find any element. How can I find the last <div>
element which contains a child <message-content>
?