title: How to execute the command after each javascript statement in a block?
body: <p>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.</p>
  <p><strong>THE BLOCK CODE</strong></p>
  <pre><code>function sleep(delay) {
      var start = new Date().getTime();
      while (new Date().getTime() &lt; start + delay);
  }
  
  
  for(var i=0;i&lt;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();
  }
  
  </code></pre>
  <p>I get every time the following error: <code>TypeError: undefined is not an object (evaluating 'document.getElementsByClassName('artdeco-dropdown__content-inner')[0].getElementsByTagName')</code></p>
  <p>It seems that after <code>Click on connection</code> 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).</p>