[英]How to make correct loop in CasperJS?
var casper = require('casper').create();
casper.start();
casper.then(function(){
for(var i=1;i<3;i++){
this.repeat(3,function(){
this.echo("loop iteration!");
});
this.echo("hello");
}
});
casper.run()
输出:
你好,你好循环迭代! 循环迭代! 循环迭代! 循环迭代! 循环迭代! 循环迭代!
为什么先打“ hello”?
如何将循环写为同步循环?
Artjom是正确的。 您必须使用then()。 就像是:
for(var i=1;i<3;i++){
this.repeat(3,function(){
this.echo("loop iteration!");
});
this.then(function(){
this.echo("hello");
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.