B
B
betsbi2018-06-11 17:48:27
PhantomJS
betsbi, 2018-06-11 17:48:27

Casperjs function each returns only the last element?

var casper = require('casper').create({
  pageSettings: {
    userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
  }
});
var links = [
    "http://google.com/",
    "http://bing.com/",
    "http://yahoo.com/",
];
casper.start();
casper.each(links, function (self, link) {
        self.thenOpen(link, function () {
            this.echo(this.getTitle() + " - " + link);
        });
    });
    casper.run();

Here is what I get in the browser:
Yahoo - yahoo.com
title google and bing I don't get
Also phantomjs also returns the last element of the list (links)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question