Ask Your Question
3

What is the procedure for choosing the subsequent HTML element in Puppeteer by utilizing $$. or $$eval?

asked 2023-05-13 13:36:48 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2023-05-13 13:56:01 +0000

scrum gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-13 13:36:48 +0000

Seen: 9 times

Last updated: May 13 '23