I am new to CasperJS, but there is no way to open the URL and execute CasperJS commands for loops? For example, this code does not work as I expected:
casper.then(function() {
var counter = 2013;
for (i = counter; i < 2014; i++) {
var file_name = "./Draws/wimbledon_draw_" + counter + ".json";
var json = require(file_name);
var first_round = json["1"];
for (var key in first_round) {
var name = first_round[key].player_1.replace(/\s+/g, '-');
var normal_url = "http://www.atpworldtour.com/Tennis/Players/" + name;
casper.thenOpen(normal_url, function() {
this.echo(normal_url);
});
}
}
});
Instead, Casper is called thenOpenfor iteration for each new URL, it is called only after the for loop is executed. Casper thenOpenthen receives a call with the last value of normal_url. Is there a Casper command to work on every iteration in a for loop?
Procedure: How to make casper thenOpen return the value of the current iteration of the for loop?
Say, for example, I needed a return value for this thenOpen(maybe if the HTTP status is 404, I need to evaluate a different URL, so I want to return false). Can this be done?
casper.thenOpen :
var status;
casper.thenOpen(normal_url, function() {
status = this.status(false)['currentHTTPStatus'];
if (status == 200) {
return true;
} else {
return false;
}
});
console.log(status);