user3255100
user3255100

Reputation: 31

CasperJS back navigation doesn't work?

Here's the situation:

  1. I use CasperJS to open a page
  2. I click on button on the page to go to page2
  3. I click a button on page2 to go to page3

Now I am on page 3 and I call this.back() within a then statement and it does go back to page 2 and everything just stops executing after that

I also tried to call

this.then(function() {
    this.evaluate(function() {
        history.go(-1);
    });
});

and it goes back to page2 and gets stuck again. The next line won't execute.

Any ideas or is this a bug?

Upvotes: 3

Views: 1298

Answers (2)

Grant Miller
Grant Miller

Reputation: 28989

You can also access the existing PhantomJS WebPage instance via page and call the goBack() method:

casper.then(function () {
  this.page.goBack();
});

Upvotes: 0

Diego Borges
Diego Borges

Reputation: 342

Typically, the following code works for me:

casper.then(function () {
    this.back();
});

Make sure you are running on a step your code and finally, in a separate step, the step of returning the page. This is necessary so that your .back be done AFTER your code.

Upvotes: 3

Related Questions