n1k0/casperjs — Issue #47: Need two 'then' after a submit
Author: marchugon
Created: 2012-01-30 15:14:10+00:00
State: open

Hello

I'm using the latest version of casperjs (0.6.2) and phantomjs 1.4.1

I fill a form with various data :

```javascript
...
this.fill('form#form-infos-complementaires', {'prenom' : 'firstnameTest'}, false);
this.fill('form#form-infos-complementaires', {'nom' : 'nameTest'}, false);
...
```

I tried to emulate the click on a button, but it doesn't work with this king of ugly html code :

```javascript

```

So I tried submitting the form like this :

```javascript
this.evaluate(function(){document.querySelector('form#form-infos-complementaires').submit();});
```

In order to make it work, I must do something like this :

```javascript
...
casper.then(function() {
this.fill('form#form-infos-complementaires', {'prenom' : 'firstnameTest'}, false);
this.fill('form#form-infos-complementaires', {'nom' : 'nameTest'}, false);
this.evaluate(function(){document.querySelector('form#form-infos-complementaires').submit();});
});
//method called immediately after the previous one, nothing is sent to the server
casper.then(function() {
this.test.info('return code is '+this.currentHTTPStatus+', current URL is '+this.getCurrentUrl());
});
//now I see my form sent, isnt't it strange ?
casper.then(function() {
this.test.info('return code is '+this.currentHTTPStatus+', current URL is '+this.getCurrentUrl());
});
...
```

The POST mechanism seems only triggered by the second "then".... any idea what may cause this behaviour ?