0

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();
    
})()  
TylerH
  • 20,799
  • 66
  • 75
  • 101
Jade Sage
  • 11
  • 2
  • You can't return DOM nodes from `$eval` because they're not serializable. Try `await page.$$eval('.container > *', els => els.map(el => el.textContent));`. – ggorlen Dec 08 '22 at 15:15

0 Answers0