The following code works as advertised:
var links = [];
var processPage = function() {
links = links.concat(this.evaluate(getLinks));
};
function getLinks() {
var links = document.querySelectorAll('h3.r a');
return Array.prototype.map.call(links, function(e) {
return e.href;
});
return links;
}
....
casper.start();
casper.thenOpen(link).waitForText('Some Text', processPage);
casper.run();
But, if I want to be selective about the links accumulated and I adjust the getLinks method as follows:
function getLinks() {
var links = document.querySelectorAll('h3.r a');
return Array.prototype.map.call(links, function(e) {
if (e.text === 'Some Text') {
return e.href;
}
});
return links;
}
Seems a reasonable thing to do, however, the function returns nothing. e.text contains valid data.
I might have the wrong end of the Javascript stick here because I'm relatively new at this stuff. Maybe it has something to do with what happens when the if statement is false. In that case, I don't know how to handle that one.
Would appreciate it if I could be pointed in the right direction.