CasperJS getElementsByXPath only returning first element

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?


通过Casper / PhantomJS evaluate()函数,您必须将原生DOM元素和元素列表映射到JSON序列化的东西:

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);
链接地址: http://www.djcxy.com/p/66264.html

上一篇: 点击可编辑textview

下一篇: CasperJS getElementsByXPath只返回第一个元素