0

Let's say I will go to google.com then fetch all a tags inside the page, so I write something as below

await page
  .goto ("https://google.com")
  .then (() => page.$$eval ("a", xs => xs.length))
  .then (console.log)

this will print a number that's greater than 0, which means that xs is an array full of <a> html elements. Good

However once I change it to the following

await page
  .goto ("https://google.com")
  .then (() => page.$$eval ("a", xs => xs))
  .then (console.log)

it returns undefined ??? this is weird and confusing why would it return undefined it doesn't make any sense

is this a bug or something !

Focus
  • 117
  • 9
  • It does make sense. DOM nodes aren't serializable, and you can't do anything with them back in NodeJS, only in the browser. – ggorlen Nov 15 '22 at 15:14
  • Does this answer your question? [Get elements from page.evaluate in Puppeteer?](https://stackoverflow.com/questions/53032903/get-elements-from-page-evaluate-in-puppeteer). Also [Puppeteer evaluate returns undefined](https://stackoverflow.com/questions/64216965/puppeteer-evaluate-returns-undefined) and others. – ggorlen Nov 15 '22 at 15:16
  • @ggorlen Thank you for your reply. It makes sense now however **it should be mentioned in the documentation !** From the official docs: *"If it returns an element it is wrapped in an ElementHandle, else the raw value itself is returned."* `the raw value itself`?? not undefined ... this is why it was confusing I will update with an answer to help whoever comes to this problem in the future – Focus Nov 15 '22 at 19:31
  • You can make a PR for the docs if you're not happy with the description. – ggorlen Nov 16 '22 at 01:47

0 Answers0