I am current trying to use Puppeteer to access the innerText of child elements with await page.$eval('.container')
, but am unable to get any properties when I console.log the result. All I get are empty objects like this { '0': {}, '1': {}, '2': {} }
. Below is an example of the HTML I am trying to get the innerText from.
<div class="container">
<div class="child">A</div>
<div class="child">B</div>
<div class="child">C</div>
</div>
The code I've tried so far
import puppeteer,{ executablePath } from "puppeteer"
(async () => {
const browser = await puppeteer.launch({
headless: true,
executablePath: executablePath(),
});
const page = await browser.newPage();
await page.goto('http://localhost:5000/test_child.html',{
waitUntil: 'networkidle2',
});
let child = await page.$eval('.container', e =>e.children);
console.log(child)
await browser.close();
})()