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

127
Views
JavaScript wait for click

I have x - pages of lists of 15 objects each. I would like to go through all the pages downloading the text of each of the 15 items in the list. The download works, but the same elements are written to the variable "a" (probably because the code executes faster than clicking from within the code). Is it possible to put it to sleep / wait for execution and then go to the next page?

var a = '';
for (let i = 0; i < 999; i++) {
    const paragraphs = document.querySelectorAll(".my-object-on-list");
    paragraphs.forEach(p => a = a + p.outerText);
    angular.element(document.getElementsByClassName('btn-forward')).click();
    setTimeout(1);//sleep for 1s?
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are many problems in your script

Try this

const paragraphs = document.querySelectorAll(".my-object-on-list");
cons ctn = 0;
const btn = document.getElementsByClassName('btn-forward')
let a = []
const run() {
  if (cnt >= paragraphs.length) {
    processResults();
    return 
  }
  a.push(p.outerText);
  angular.element(btn).click();
  cnt++
  setTimeout(run,3000);
}
run()

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!