I'm trying to get an object from a web page through the evaluate()
method so I can work with it outside the scope of evaluate
. The element selected with name symbol
is a <select>
tag with 148 <options>
(=dropdown menu).
casper.then(function () {
var elmnt = this.evaluate(function () { return document.getElementsByName("symbol")[0]; });
console.log(elmnt.options[14].index);
});
//Returns TypeError: 'null' is not an object (evaluating 'elmnt.options[14].index')
casper.then(function () {
var elmnt = this.evaluate(function () { return document.getElementsByName("symbol")[0].options[14].index; });
console.log(elmnt);
});
//Returns 14
So it looks likes returning an object through the evaluate()
method returns it incompletly since this works correctly :
casper.then(function () {
var elmnt = this.evaluate(function () { return document.getElementsByName("symbol")[0]; });
console.log(elmnt.options.length);
});
//Returns 148
So I can access options attributes as long as I don't read the array. Strange no ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…