3

When I try to navigate the pagination on sites with links where href is a __doPostBack function call, I never achieve the page change.

I am not sure what I am missing, so after a few hours of messing around I decided to see if someone here can give me a clue. This is my code (uber-simplified to show the use case).

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug"
});
casper.start('http://www.gallito.com.uy/inmuebles/venta');
// here i simulate the click on a  link in the pagination list
casper.evaluate(function() {
    __doPostBack('RptPagerDos$ctl08$lnkPage2','');
});
casper.then(function() {
    console.log(' new location is ' + this.getCurrentUrl());
    var i=casper.evaluate(function(){
        return $(".aspNetDisabled").text();
    });
    console.log(i);
});
casper.run();

I tried with casper's click() and a simple jQuery click on evaluate, but that does not work because the href is a call to the __doPostBack function.

I am using casperjs 1.1.0-beta3 and phantomjs 1.9.7. I checked for similar issues and I saw this post CasperJS : how to call __doPostBack but the solution there does not work for me, and apparently it did not work for the OP either.

Thanks in advance. Please let me know if you need any more details.

rowasc
  • 320
  • 1
  • 3
  • 10
  • It is just a suspicion, but I think that phantomjs cannot parse XHTML properly. That is why invoking `__doPostBack` shows the error msg *ReferenceError: Can't find variable: __doPostBack* when listening to [`page.error`](http://docs.casperjs.org/en/latest/events-filters.html#page-error) event. – Artjom B. Aug 03 '14 at 22:43
  • 1
    Take a look at this: https://groups.google.com/forum/#!msg/casperjs/RpDvMXGyjc8/aAoLOvGAe6UJ I was able to follow the working code to get my thing working. – James O'Brien Sep 04 '14 at 20:27

1 Answers1

1

I was able to navigate the pagination by changing

casper.evaluate(function() {
    __doPostBack('RptPagerDos$ctl08$lnkPage2','');
});

To this:

casper.then(
    function(){
        casper.evaluate(   function() {
            var insertHTML='<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /><input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />';
            $("#Form1 .aspNetHidden").html(insertHTML);

            $("#Form1 .aspNetHidden #__EVENTTARGET").val('RptPagerDos$ctl04$lnkPage2');


            $("#Form1").submit();

        });
    }
);

I noticed that even trying to submit the form directly was a problem, it looks like for some reason, it was not finding the elements it needed (i tried casper's fill() function and got crashes because the form inputs were not present)

rowasc
  • 320
  • 1
  • 3
  • 10
  • Those are hidden fields, so you cannot `fill` them. – Artjom B. Aug 03 '14 at 22:35
  • Actually, casper was not even aware that they were there, since I tried getting the HTML of the .aspNetHidden div with .getHTML() and it was empty. Is that another limitation ? Thanks – rowasc Aug 03 '14 at 22:37