Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To choose the subsequent HTML element in Puppeteer by utilizing $$. or $$eval, you need to follow the below procedure:

  1. First, you need to call the page.evaluate() method in Puppeteer.

  2. After that, you can use any of the following functions: $$.() or $$eval().

  3. The $$.() function allows you to select all the DOM elements that match the given selector. For example, $$('.classname') will select all the elements having the class ‘classname.'

  4. The $$eval() function allows you to evaluate a function on each of the selected elements. For example, $$eval('a', el => el.href) will return the href attribute value of each ‘a’ element.

  5. Once you have selected or evaluated the subsequent HTML element, you can perform any further actions on it as needed.

Note: It is always recommended to use the page.waitForSelector() method before selecting the subsequent elements to make sure that the required element is loaded and available in the DOM.