CasperJS back navigation is not working

297 views Asked by At

This is my code, the back navigation is not working, because the screen capture is same as previous even though I waited for 2 seconds.

phantom.casperPath = "/Users/manoj/apply_robots/casjs/casperjs";
phantom.injectJs(phantom.casperPath + "/bin/bootstrap.js");
phantom.injectJs("/Users/manoj/apply_robots/jquery/jquery-2.1.4.min.js");

var utils = require('utils');
var fs = require('fs');
var a;
var flag = 1;

var casper = require('casper').create();
casper.userAgent("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16");
var x = require('casper').selectXPath;

casper.start('https://piedmont.taleo.net/careersection/2/moresearch.ftl?lang=en',function(){

    casper.page.injectJs('/Users/manoj/apply_robots/jquery/jquery-2.1.4.min.js');
    this.echo(this.getTitle());
    this.evaluate(function() {
        document.querySelector('#requisitionListInterface\\.dropListSize').selectedIndex = 4;
        return true;
    });

    this.wait(3000,function(){});
});

casper.then(function(){
    this.thenClick(x('//*[@id="requisitionListInterface.pagerDivID4117.Next"]')).then(function() { 

        this.wait(2000,function(){
            this.capture("i1.png");
        });
    });
});

casper.then(function () {
    this.echo("inside back");
    this.back();
    this.wait(3000,function(){
        this.capture("i3.png");
    });
});

casper.then(function(){
    this.thenClick(x('//*[@id="requisitionListInterface.pagerDivID4117.Next"]')).then(function() { 
        this.wait(2000,function(){
            this.capture("i5.png");
        });
    });
});
1

There are 1 answers

0
Artjom B. On BEST ANSWER

Sometimes it is necessary to execute the back() call twice in order for it to work:

casper.back().back();

I don't know why this is the case, but it may be related to redirection which means that when back() is called, the previous page is loaded that is only a redirect to the page from where back() was called. Calling back() a second time loads the page before the redirection page.