casperjs evaluate function not working

admin

Administrator
Staff member
I am working on casperjs. I write following program to get output:

Code:
var casper = require('casper').create();
var cookie;
casper.start('http://wordpress.org/');
casper.then(function() {
       this.evaluate(function() {
            cookie=document.cookie;
       })
   })

casper.then(function() {
console.log("Page cookie");
console.log(cookie);
})
casper.run(function() {
 this.echo('Done.').exit();
})

Output for above is:<br/>
Page cookie<br/>
undefined<br/>
Done.

why it give me undefined? Help me into this.