Casperjs how to get to next page

I'm just beginning with casperjs and js trying to get it to navigate to a new page.

There are multiple similar links on the page that look like this:

<a href="#" onclick="GoToPage(1)"><font class="IndexLink">2</font></a>
<a href="#" onclick="GoToPage(2)"><font class="IndexLink">2</font></a>
<a href="#" onclick="GoToPage(3)"><font class="IndexLink">2</font></a>
<a href="#" onclick="GoToPage(4)"><font class="IndexLink">2</font></a>
.etc.

I am on page 1 trying to go to page 2. Here is the partial code:

pageNumber=2;   // hard coded for now.
var target = 'a[onclick="GoToPage('+ pageNumber + ')"]';
this.test.assertSelectorExists(target);
this.click(target);

I'm doing the test to assure myself that the selector is valid and the test passes. In the debug output I see that the url change is requested but it seems to go to the same page it is on instead of page 2.

For what it's worth here is the debug output for this segment of code:

PASS Found an element matching: a[onclick="GoToPage(2)"] [debug] [phantom] Mouse event 'click' on selector: a[onclick="GoToPage(2)"] [debug] [phantom] Navigation requested: url=http://www.clermontauditorrealestate.org/search/advancedsearch.aspx?mode=advanced#, type=LinkClicked, lock=true, isMainFrame=true [debug] [phantom] url changed to "http://www.clermontauditorrealestate.org/search/advancedsearch.aspx?mode=advanced#" [info] [phantom] Step 5/6: done in 2880ms. [info] [phantom] Step 6/6 http://www.clermontauditorrealestate.org/search/advancedsearch.aspx?mode=advanced# (HTTP 200) [debug] [phantom] Capturing page to /Users/willirl/a-will-1-screenshot.png

This is a public web site I'm scraping so I can post the full 20 or so lines of code if that would help.

Any help is appreciated.

Upvotes: 0

Views: 1677

Answers (1)

chillix
chillix

Reputation: 11

How dou you dedect if a new page is loaded, instantly after the click?

If yes, I recommend using thenClick and then to do some actions after it. Notice that you will have to call run() for your instance if you want to execute the start of the instance and all the then-steps

Upvotes: 0

Related Questions