Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Iterate through all elements on a div and click on each on Puppeteer

I'm trying to get the data inside of every page from a list and would like help to iterate through all the elements with Puppeteer.

I'm accessing an element with the following code:

await page.waitForSelector('#element')
      .then(() => console.log("got it"))
      .catch(e => {
        console.log("Error: " + e);
      });

This #element is populated with a span that has around 20 div (child) with a clsas of .li like below:

<div id="element">

    <div id="other">
    </div>

    <span id="listofitemstoclick">

        <div class="li">

        </div>

            <div class="li">
            
            </div>

                <div class="li">
            
                </div>
                      ...
    </span>
</div>

I need to click on the first, go back, click on the second, and so on.

Any approach that would be good here?

As the .li doesn't have any href, I believe I need to get each child and click one by one, but yet couldn't find any good way to retrieve each child, click, go back and click on the next.

Appreciate the help!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!