Rustem Rustem - 1 year ago 159
Javascript Question

console.log doesn't work in CasperJS' evaluate with setTimeout

Why when I use

, it works:

casper.then(function() {
this.evaluate( function() {

But this doesn't work:

casper.then(function() {
this.evaluate( function() {
setTimeout( function() {console.log('hello');}, 1000);

Answer Source

Because you're mixing up casperjs and remote page environments. The evaluate function will execute code within the remote page env, so the console.log call won't output anything.

If you want to catch remote console.log calls, listen to the remote.message event:

casper.on('remote.message', function(msg) {
    this.echo('remote message caught: ' + msg);

Btw, documentation for events is pretty much exhaustive, as well as the one for evaluate.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download