LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   casperjs loop (https://www.linuxquestions.org/questions/programming-9/casperjs-loop-4175447263/)

babbab 01-25-2013 11:41 PM

casperjs loop
 
Hi I've been reading doc for days and ended up here to ask.

Is there good way to define function in casperjs
and repeat the function as many as count of array variable

ex.
Code:

var links = ['link1', 'link2'...]

ciotog 04-30-2013 03:41 PM

It seems to be mentioned in the main API doc here:
http://casperjs.org/api.html#casper.each

Code:

Casper#each(Array array, Function fn)
Iterates over provided array items and execute a callback.

Example:

var links = [
    'http://google.com/',
    'http://yahoo.com/',
    'http://bing.com/'
];

casper.start().each(links, function(self, link) {
    self.thenOpen(link, function() {
        this.echo(this.getTitle());
    });
});

casper.run();



All times are GMT -5. The time now is 10:11 PM.