I have a list of links that I have to simulate a click on using CasperJS. They all share the same class.
However using this.click(\'.click-me\') only cl
As proposed on the CasperJS ML and for the records, here's a possible implementation of clickWhileSelector:
var casper = require('casper').create();
casper.clickWhileSelector = function(selector) {
return this.then(function() {
if (this.exists(selector)) {
this.echo('found link: ' + this.getElementInfo(selector).tag);
this.click(selector);
return this.clickWhileSelector(selector);
}
return this.echo('Done.').exit();
});
}
casper.start().then(function() {
this.page.content =
'' +
'link 1' +
'link 2' +
'link 3' +
'';
});
casper.clickWhileSelector('a').run();
That gives:
$ casperjs c.js
found link: link 1
found link: link 2
found link: link 3
Done.