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

315
Views
How to execute the command after each javascript statement in a block?

I want to remove some connection from a Social Media account using JavaScript. If I execute the statements line by line, it works perfectly, but when I execute them in a block of code, it doesn't work.

THE BLOCK CODE

function sleep(delay) {
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}


for(var i=0;i<5;i++) {
    //Click on connection
    sleep(1000);
    document.getElementsByClassName('reusable-search__entity-result-list list-style-none')[0].getElementsByClassName('entity-result__title-text t-16')[1].getElementsByClassName('app-aware-link')[0].click();
    sleep(1000);
    //Remove connection button
    document.getElementsByClassName('ivm-view-attr__img--centered EntityPhoto-circle-3 lazy-image ember-view')[1].click();
    sleep(1000);
    document.getElementsByClassName('artdeco-dropdown__content-inner')[0].getElementsByTagName('li')[6].getElementsByClassName('pvs-profile-actions__action display-flex align-items-center artdeco-dropdown__item artdeco-dropdown__item--is-dropdown ember-view')[0].click();
    //Back
    sleep(1000);
    history.back();
}

I get every time the following error: TypeError: undefined is not an object (evaluating 'document.getElementsByClassName('artdeco-dropdown__content-inner')[0].getElementsByTagName')

It seems that after Click on connection part, the page is not loading, and it does only after the block is done. (I tried also without for loop, only those statements, but it happened the same like in the loop).

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!