Brice LALU
Brice LALU

Reputation: 173

Random failure with "click" on casperjs and phantomjs

I don't understand, once on ten when i execute this code:

casper.then(function() {
        this.waitUntilVisible('#selector');
});
casper.then(function() {
       this.evaluate(function() {
           $('#selector').click();
       });
});

click function doest not work, but the selector is present, i see that on my screenshot (I have automatic capture when something fail in my tests).

I also try the casper.click() function but I have the same random result.

Upvotes: 1

Views: 293

Answers (1)

Brice Favre
Brice Favre

Reputation: 1527

I suggest to replace then by a wait function.

For example replace in your code :

casper.then(function() {

by

casper.waitForSelector('#selector', function() {

You will find more information about waitForSelector in the documentation : http://docs.casperjs.org/en/latest/modules/casper.html#waitforselector

Upvotes: 1

Related Questions