javascript - CasperJS doesn't follow link on an ASP site -


i'm trying mimic browser behavior on site built asp, seems use lot of javascript based links , ui using casperjs. i'm pretty stuck, , not sure how next.

i'm using:casperjs1.1.0-beta3,phantomjs1.9.8, , site url https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx

this html link want click on:

<td>     <a href="javascript:__dopostback('ctl00$m$g_ba040fcb_44f7_44fa_92d0_d088c5679794$ctl00$gvcasedetails','page$3')">3</a> </td> 

the site has ssl configuration problems, casperjs run additional flags work: casperjs --ignore-ssl-errors=true --ssl-protocol=tlsv1 icsid.js

icsid.js tries open site , click on link next page of results. want check results.

var casper = require('casper').create({     clientscripts: ["./jquery.min.js"],     verbose: true,     loglevel: 'debug',     pagesettings: {         loadimages: false,         loadplugins: false,         useragent: 'mozilla/5.0 (windows nt 6.2; wow64) applewebkit/537.36 (khtml, gecko) chrome/29.0.1547.2 safari/537.36',     } });  casper.start('https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx', function(){});  casper.then(function() {     this.wait(5000);     this.capture('screenshot0.png');     casper.then(function(){         var text = this.evaluate(function(){             return jquery('.gdcol a')[0].text;         });         console.log('text: ' + text);          this.evaluate(function(){             // try go second page             return jquery('a').filter(function(index) { return $(this).text() === "2"; })[0].click();         });     });       casper.then(function(){         this.wait(5000);          var size = this.evaluate(function(){             return jquery('.gdcol a').size();         });         console.log('size: ' + size);          // if clicked , changed url, link text change         var text = this.evaluate(function(){             return jquery('.gdcol a')[0].text;         });         console.log('text: ' + text);          // if it's still on first page, null         var page = this.evaluate(function(){             return jquery('a').filter(function(index) { return $(this).text() === "1"; })[0].text;         });         console.log('page: ' + page);          // if it's on second page, null         var page = this.evaluate(function(){             return jquery('a').filter(function(index) { return $(this).text() === "2"; })[0].text;         });         console.log('page: ' + page);          this.capture('screenshot1.png');     }); });  casper.run(); 

this resulting log:

[info] [phantom] starting... [info] [phantom] running suite: 3 steps [debug] [phantom] opening url: https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx, http [debug] [phantom] navigation requested: url=https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx, type=other, willnavigate=true, ismainframe=true [debug] [phantom] url changed "https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx" 2015-07-23 11:48:31.255 phantomjs[10699:d13] coretext performance note: client called ctfontcreatewithname() using name "arial" , got font postscript name "arialmt". best performance, use postscript names when calling api. 2015-07-23 11:48:31.256 phantomjs[10699:d13] coretext performance note: set breakpoint on ctfontlogsuboptimalrequest debug. 2015-07-23 11:48:31.278 phantomjs[10699:d13] coretext performance note: client called ctfontcreatewithname() using name "arial" , got font postscript name "arialmt". best performance, use postscript names when calling api. 2015-07-23 11:48:31.279 phantomjs[10699:d13] coretext performance note: client called ctfontcreatewithname() using name "arial" , got font postscript name "arialmt". best performance, use postscript names when calling api. 2015-07-23 11:48:31.280 phantomjs[10699:d13] coretext performance note: client called ctfontcreatewithname() using name "arial" , got font postscript name "arialmt". best performance, use postscript names when calling api. 2015-07-23 11:48:31.280 phantomjs[10699:d13] coretext performance note: client called ctfontcreatewithname() using name "arial" , got font postscript name "arialmt". best performance, use postscript names when calling api. 2015-07-23 11:48:31.479 phantomjs[10699:d13] coretext performance note: client called ctfontcreatewithname() using name "arial" , got font postscript name "arialmt". best performance, use postscript names when calling api. 2015-07-23 11:48:31.480 phantomjs[10699:d13] coretext performance note: client called ctfontcreatewithname() using name "arial" , got font postscript name "arialmt". best performance, use postscript names when calling api. [debug] [phantom] automatically injected ./jquery.min.js client side [debug] [phantom] injected casper client-side utilities [info] [phantom] step anonymous 2/3 https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx (http 200) [info] [phantom] step anonymous 2/3: done in 1886ms. [info] [phantom] step anonymous 3/3 https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx (http 200) [debug] [phantom] capturing page /users/yubrew/app/lib/tasks/screenshot0.png [info] [phantom] capture saved /users/yubrew/app/lib/tasks/screenshot0.png [info] [phantom] step anonymous 3/3: done in 2347ms. [info] [phantom] step _step 4/6 https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx (http 200) [info] [phantom] step _step 4/6: done in 2351ms. [info] [phantom] wait() finished waiting 5000ms. [info] [phantom] step anonymous 5/6 https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx (http 200) text: arb/15/30 [info] [phantom] step anonymous 5/6: done in 7377ms. [info] [phantom] step anonymous 6/6 https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx (http 200) size: 50 text: arb/15/30 page: null page: 2 [debug] [phantom] capturing page /users/yubrew/app/lib/tasks/screenshot1.png [info] [phantom] capture saved /users/yubrew/app/lib/tasks/screenshot1.png [info] [phantom] step anonymous 6/6: done in 7491ms. [info] [phantom] step _step 7/7 https://icsid.worldbank.org/apps/icsidweb/cases/pages/advancedsearch.aspx (http 200) [info] [phantom] step _step 7/7: done in 7493ms. [info] [phantom] wait() finished waiting 5000ms. [info] [phantom] done 7 steps in 12493ms 

note screenshots , console log indicate page contents has not changed.

you shouldn't use element.click(), because doesn't in phantomjs of time. use casperjs' click() function tries many thing click element.

since css selectors don't support matches based on text, can use xpath solve this:

var x = require('casper').selectxpath; ... casper.click(x("//a[text()='2']")); 

your other misconception casper.wait() something. then*() , wait*() functions asynchronous step functions. when call them, you're scheduling step should executed @ end of current step.

for example, if call this:

this.wait(5000); this.capture('screenshot0.png'); this.then(function(){... 

it executed this:

this.capture('screenshot0.png'); this.wait(5000); this.then(function(){... 

if can, should wrap synchronous function calls in casper.then().


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -