I use the following code to get all table cells in the first table row. I'd like to then check the innerHTML of every single table cell. But in the object returned by this function only the first table cell is actually there, all the other properties are null:
firstRow = this.evaluate(function () {
return __utils__.getElementsByXPath('//tbody/tr[1]/td');
});
utils.dump(firstRow);
The output from utils.dump is:
[
{
"abbr": "",
"align": "",
"attributes": {...}
},
null,
null,
null
]
I also tried with utils.findAll and it was the same. How can I get all the matched elements?
With Casper/PhantomJS evaluate()
functions, you have to map native DOM elements and lists of elements to something JSON-serializable:
var firstRow = this.evaluate(function () {
var elements = __utils__.getElementsByXPath('//tbody/tr[1]/td');
return [].map.call(elements, function(element) {
return element.outerHTML;
});
});
utils.dump(firstRow);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With