Can't navigate using casperjs evaluation and __doPostBack function
When I try to navigate pages on linked sites where the href is a call to the __doPostBack function, I never get to change the page.
I'm not sure what I'm missing, so after hours of messing around, I decided to see if anyone here could give me a hint. This is my code (uber-simplified to show a usage example).
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 client click () and simple jQuery to click on the score, but that doesn't 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 similar issues and I saw this CasperJS post : How to call __doPostBack , but the solution there doesn't work for me, and apparently it didn't work for the OP.
Thanks in advance. Please let me know if you need more details.
source to share
I was able to navigate through the pages by changing
casper.evaluate(function() {
__doPostBack('RptPagerDos$ctl08$lnkPage2','');
});
For 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 seems like it couldn't find the elements it needed for some reason (I tried the casper fill () function and got a crash because the form inputs weren't present)
source to share