Need to run for loop and WaitFor in sync CasperJS
I have a code as below
var casper = require('casper').create();
casper.on('remote.message', function (msg) {
this.echo(msg);
});
casper.start( << some url >> , function () {
this.echo(this.getTitle());
});
var resultObj = [];
casper.thenClick("#AddToCart").then(function () {
// scrape something else
casper.options.waitTimeout = 100000;
var objectOne = this.evaluate(someFunction, << variables >> );
//above function returns object
casper.each(objectOne, function (self, obj) {
var anotherObject = this.evaluate(anotherFunction, << variables >> );
self.waitFor(function check() {
var result = this.evaluate(thirdFunction, obj);
if (result != 'no') {
resultObj.push(result);
}
// result = 'yes';
return result != 'no';
this.evaluate(function () {});
}, function then() {
console.log('done')
});
});
});
casper.run(function () {
this.exit();
});
It cantains on loop (.each) followed by wait for. The problem that I am
facing is the loop gets executed completely ant then waitFor gets
executed. How can I achieve them to be in sync.
No comments:
Post a Comment