0

Hi I am trying to loop through a node list in an CASPERJS evaluate statement like so :

var t = this.evaluate(function() {
    var t = document.querySelectorAll('.status');
    var r = [];
    for(var x = 0; x < t.length; x ++) {
        r.push(t[x]);
    }

    return r;

})

While the array contains the correct number of entries, only the first contains a dom element, the rest returning undefined? This also happens if I return the t nodelist on it's own.

frank astin
  • 115
  • 10
  • The problem isn't in that code. Can you post an [mcve]? (BTW, that code could be `var t = this.evaluate(function() { return Array.from(document.querySelectorAll('.status')); }` or if you don't want to polyfill `Array.from` on old browsers, `var t = this.evaluate(function() { return Array.prototype.slice.call(document.querySelectorAll('.status')); }`. – T.J. Crowder Apr 21 '17 at 17:17
  • Hi TJ, I think you missing that it's running in CasperJS, the code works fine in chromes console. – frank astin Apr 21 '17 at 17:24
  • I understand it's running in CasperJS. But unless CasperJS is fundamentally broken, which I'm sure it isn't, the problem isn't in that code based on the description. – T.J. Crowder Apr 21 '17 at 17:49
  • See the duplicate – Artjom B. May 14 '17 at 12:18

0 Answers0