0

i have a puppeteer code here

//within my puppeteer file
const relatedData = await page.evaluate(() => {
    const related = Array.from(document.querySelectorAll('.CbirSites-Item'))
    return related
  });
  console.log(relatedData);
result = []

the result returns empty and i assumed it could not find the items but when i query select all within the actual browser itself it appears

//within the browser inspect console
document.querySelectorAll('.CbirSites-Item')
NodeList(20)[.......]

i expected the code to show all the items in the array but the result returned empty

  • 5
    Probably the items don't exist yet and you are checking too early, or perhaps they are in an IFrame and you didn't pay attention to the currently selected frame in your console when you tested in your browser. – CherryDT Aug 27 '23 at 17:23
  • 2
    @CherryDT Those ideas are good, but even if they're all satisfied, OP's code still won't work because they're trying to return browser nodes, which aren't serializable, back to Node. See [Puppeteer page.evaluate querySelectorAll return empty objects](https://stackoverflow.com/questions/46377955/puppeteer-page-evaluate-queryselectorall-return-empty-objects). – ggorlen Aug 27 '23 at 19:11
  • Instead of trying to return DOM's elements, you can pass to evaluate a function to elaborate the elements and to return a serializable object – giacomoto Aug 28 '23 at 21:31

0 Answers0