gabriel mellace gabriel mellace - 1 year ago 219
Javascript Question

Casperjs evaluate iteration

I want to iterate over the tr on a table using casper, but i cannot get the counter inside the evaluate function, i tried replacing the variable with a fixed number and it works.

var i =0;
for(i=1;i<amount;i++) {

var identifier = this.evaluate(function(i) {

return $("#div_identifiers_result > tr:nth-child("+i+") > td:nth-child(1)").parent().data('name');

this.echo(identifier ,'info');

how can i make the scope inside evaluate to see that i counter?

Answer Source

Try this:-

var identifier = this.evaluate(function(i) {
  return $("#div_identifiers_result > ..." + i + "...").parent().data('name'); 
}, i);

Anything inside evaluate is sandboxed and you will need to pass in any params you want to use inside

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download