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

后端 未结 4 684
Happy的楠姐
Happy的楠姐 2020-12-01 10:16

Why when I use console.log in evaluate, it works:

casper.then(function() {
  this.evaluate( function() {
    console.log(\'hello\')         


        
4条回答
  •  时光说笑
    2020-12-01 11:14

    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.

提交回复
热议问题