为什么当我在 evaluate
中使用 console.log
时,它有效:
casper.then(function() {
this.evaluate( function() {
console.log('hello');
});
});
但这行不通:
casper.then(function() {
this.evaluate( function() {
setTimeout( function() {console.log('hello');}, 1000);
});
});
最佳答案
因为您混淆了 casperjs 和远程页面环境。 evaluate
函数将在远程页面环境中执行代码,因此 console.log
调用不会输出任何内容。
如果你想捕获remote console.log
调用,监听remote.message
事件:
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
})
顺便说一句,documentation for events非常详尽,以及the one for evaluate .
关于javascript - console.log 在 CasperJS 的 setTimeout 评估中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11864373/