title: Automating file downloads using Javascript
body: <p>For a corporate website which hosts a bunch of documents, I am writing a JavaScript to download each of these documents in an automated way.</p>
  
  <p>The approach I am following is having a html file created with these links and a javascript in the page that will iterate through the links and simulate a click.</p>
  
  <p>Unfortunately, the "clicks" happen only for the first link but stops after the further.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var links = document.getElementsByTagName('a');
  for (var i = 0; i &lt; links.length; i++) {
    links[i].click();
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;a href="path1"&gt;file 1&lt;/a&gt;
  &lt;a href="path2"&gt;file 2&lt;/a&gt;
  &lt;a href="path3"&gt;file 3&lt;/a&gt;
  &lt;a href="path4"&gt;file 4&lt;/a&gt;</code></pre>
  </div>
  </div>
  </p>