3

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?

Joeytje50
  • 18,636
  • 15
  • 63
  • 95

2 Answers2

3

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.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Diego Borges
  • 342
  • 3
  • 7
0

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

casper.then(function () {
  this.page.goBack();
});
Grant Miller
  • 27,532
  • 16
  • 147
  • 165