title: CasperJS form submit not working
body: <p>I want to upload a file to a local website, the problem is that i can upload it but can't submit it.
  I take screenshot after upload and it uploads, but i cant submit it.
  The html form and CasperJs code is described below.</p>
  
  <p>HTML form:</p>
  
  <pre><code>&lt;form method="post" action="http://127.0.0.1/" enctype="multipart/form-data"&gt;
      &lt;input type="file"   name="pict"&gt;
      &amp;nbsp;Name:&amp;nbsp;(optional)&amp;nbsp;&lt;input type="text"   name="image_platform"&gt;
      &lt;input type="submit" value="Send"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>CasperJS code for uploading the image:</p>
  
  <pre><code>casper.then(function(){
        this.evaluate(function(fileName) {__utils__.findOne('input[type="file"]').setAttribute('value',fileName)},{fileName:fileName});
        this.echo('Name='+this.evaluate(function() {return __utils__.findOne('input[type="file"]').getAttribute('name')}));
        this.echo('Value='+this.evaluate(function() {return __utils__.findOne('input[type="file"]').getAttribute('value')}));
        this.page.uploadFile('input[type="file"]',fileName);
        this.wait(1000, function() {
              this.click(x('//html/body/form/input[3]'));
        });
  });
  </code></pre>
  
  <p>CasperJS code for submitting form which doesn't work:</p>
  
  <pre><code>casper.thenEvaluate(function() {
      document.forms[0].submit();
  });
  </code></pre>
  
  <p>or</p>
  
  <pre><code>casper.then(function(){
      casper.click(x('/html/body/form/input[3]'));
  });
  </code></pre>
  
  <p>This is the HTML:</p>
  
  <pre><code>&lt;img src="logo.jpg"&gt;
  &lt;h1&gt;Program located on server test file&lt;/h1&gt;
  &lt;p&gt;This test will ensure that Program located on server is working correctly&lt;/p&gt;
  &lt;p&gt;First, make sure Program located on server is running and at least one image type is selected (see below)&lt;/p&gt;
  &lt;p&gt;Make sure that you have use host file redirect selected from the settings menu.&lt;/p&gt;
  &lt;p&gt;Click 'Browse' or 'Choose File' and navigate to \lalalanomeaning\file&lt;/p&gt;
  &lt;p&gt;Then select any type&amp;lt;XX&amp;gt; folder and select image.gif&lt;/p&gt;
  &lt;p&gt;Then click 'Send'&lt;/p&gt;
  &lt;p&gt;You should receive a response like this:&lt;/p&gt;
  &lt;p&gt;200|593430|1539|0|0|&amp;lt;answer here&amp;gt;&lt;/p&gt;
  &lt;form 
   method="post" 
   action="http://127.0.0.1/" 
   enctype="multipart/form-data"&gt;
   &lt;input type="file"   name="pict"&gt;
   &amp;nbsp;Name:&amp;nbsp;(optional)&amp;nbsp;&lt;input type="text"   name="image_platform"&gt;
   &lt;input type="submit" value="Send"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is the CasperJS code:</p>
  
  <pre><code>var casper = require('casper').create();
  var x = require('casper').selectXPath;
  casper.userAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36')
  casper.start('file:///C:/Users/myname/Desktop/cs/test.html', function() {
      this.echo(this.getTitle());
  }).viewport(1200,1000);
  
  //casper.then(function(){
  //  casper.click(x('/html/body/form/input[1]'));
  //});
  
  var webPage = require('webpage');
  var page = webPage.create();
  var fileName ='C:\\Users\\myname\\Desktop\\cs\\dm.png';
  
  casper.then(function(){
    this.evaluate(function(fileName) {__utils__.findOne('input[type="file"]').setAttribute('value',fileName)},{fileName:fileName});
    this.echo('Name='+this.evaluate(function() {return __utils__.findOne('input[type="file"]').getAttribute('name')}));
    this.echo('Value='+this.evaluate(function() {return __utils__.findOne('input[type="file"]').getAttribute('value')}));
    this.page.uploadFile('input[type="file"]',fileName);
    this.wait(1000, function() {
          this.click(x('//html/body/form/input[3]'));
      });
  });
  
  //casper.thenEvaluate(function() {
  //    document.forms[0].submit();
  //});
  
  casper.wait(7000, function(){
      casper.capture('caca.png');
  });
  casper.run();
  </code></pre>
  
  <p>I can't upload picture but I will try to explain as best as I can.</p>
  
  <p>The image is uploading...</p>
  
  <p>I cannot submit the form either by clicking or by javascript.</p>