title: Nesting casper.js actions in a loop
body: <p>I'm trying to nest casper.then() actions in a while loop. However, It seems that the script never executes the code inside those casper.then() functions.</p>
  
  <p>Here's my code</p>
  
  <pre><code>    casper.then(function() {
        while (this.exists(x('//a[text()="Page suivante"]'))) {
  
          this.then(function() {
            this.click(x('//a[text()="Page suivante"]'))
          });
  
          this.then(function() {          
            infos = this.evaluate(getInfos);
          });
  
          this.then(function() {
            infos.map(printFile);
            fs.write(myfile, "\n", 'a');
          });
        }
      });
  </code></pre>
  
  <p>Am I missing something ? </p>