title: How to submit a form using PhantomJS
body: <p>I'm trying to use phantomJS (what an awesome tool btw!) to submit a form for a page that I have login credentials for, and then output the content of the destination page to stdout. I'm able to access the form and set its values successfully using phantom, but I'm not quite sure what the right syntax is to submit the form and output the content of the subsequent page. What I have so far is:</p>
  <pre><code>var page = new WebPage();
  var url = phantom.args[0];
  
  page.open(url, function (status) {
  
    if (status !== 'success') {
        console.log('Unable to access network');
    } else {
  
      console.log(page.evaluate(function () {
  
        var arr = document.getElementsByClassName(&quot;login-form&quot;);
        var i;
  
        for (i=0; i &lt; arr.length; i++) {
  
          if (arr[i].getAttribute('method') == &quot;POST&quot;) {
            arr[i].elements[&quot;email&quot;].value=&quot;mylogin@somedomain.example&quot;;
            arr[i].elements[&quot;password&quot;].value=&quot;mypassword&quot;;
  
            // This part doesn't seem to work. It returns the content
            // of the current page, not the content of the page after
            // the submit has been executed. Am I correctly instrumenting
            // the submit in Phantom?
            arr[i].submit();
            return document.querySelectorAll('html')[0].outerHTML;
          }
  
        }
  
        return &quot;failed :-(&quot;;
  
      }));
    }
  
    phantom.exit();
  }
  </code></pre>