title: Click a button to download a file using CasperJS
body: <p>I want to write unit tests to download a file by clicking a form button using casperJS. I tried using <code>document.getElementsByTagName
  </code>to get to the button and clicked it in JavaScript's way. But I got an error message:</p>
  
  <pre><code>TypeError: 'undefined' is not a function (evaluating 'inputs[1].click()')
  </code></pre>
  
  <p>The segment of the code that didn't pass the test : </p>
  
  <pre><code>casper.then(function() {
      var inputs = document.getElementsByTagName('input');
      inputs[1].click();
  });
  </code></pre>
  
  <p>When I tried executing the same code from the console in my browser, the button got clicked and the download window popped up. </p>
  
  <p>I initially tried to check with the presence of the button with <code>assertExists</code> function in casperJS. The assertion passed, indicating that the button exists. Also, inputs array has 2 elements, one is hidden input of CSRF token (I'm using Django) and the other is the button that I want to click.</p>