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

76
Views
scrollIntoView() looping element on puppeteer

I want to scrape a list of posts while the page scroll is infinite loading. I want scrollIntoView() for each element in the loop. my code is temporarily like this and the result when the page is loaded, it bounces out but no error.

for (let i = 0; i < 20; i++) {
    const selector = 'div[role="feed"]:nth-child(2) div.sjgh65i0'

    await page.evaluate((selector, i) => {
      setTimeout(() => {
        const element = document.querySelectorAll(selector)[i]
        if(element) {
          element.scrollIntoView();
        }
      }, 2000);
    }, selector, i)
  }

For example, I want to take 20 posts and then the scraper will take the posts one by one.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

With your current flow, all timeouts are set almost at once and then all fire after the same 2 sec.

Try something like this:

const selector = 'div[role="feed"]:nth-child(2) div.sjgh65i0';

for (let i = 0; i < 20; i++) {
  await page.waitForTimeout(2000);

  await page.evaluate((selector, i) => {
    const element = document.querySelectorAll(selector)[i];
    if(element) {
      element.scrollIntoView();
    }
  }, selector, i);
}
about 4 years ago · Juan Pablo Isaza Report
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!