Var casper = require (' Casper '). Create ({clientscripts:["jquery.js"],pagesettings:{// useragent: ' mozilla/5.0 (compatible; msie 9.0; windows nt 6.1; win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .net clr 3.0.30729; media center pc 6.0; infopath.3; . net4.0c; tablet pc 2.0; . net4.0e) ' useragent: ' mozilla/4.0 (compatible; msie 8.0; windows nt 6.1; wow64; trident/4.0; slcc2; .net clr 2.0.50727; .net clr 3.5.30729; .net clr 3.0.30729; media center pc 6.0; . net4.0c; infopath.3) '}}); Var fs = require (' FS '); Var code;casper.start (' http:// Www.jsjtxx.com/spage/Beginner-Login.html '); Casper.then (function () { This.wait (5000,function ()   { this.echo ("I ' ve waited for 5 Seconds again "); }); }); //login page casper.then (function () {if (this.exists ("#ttt")) {this.capture ("Code.jpeg"); };}); Casper.then (function () { this.wait (30000,function () { this.echo ("I ' ve waited for 30 seconds again , Please input code "); }); }); // According to the input verification code to the Code.txt file and read the Casper.then (function () {if (fs.exists ("Code.jpeg") && fs.exists (" Code.txt ")) {code = fs.read (" Code.txt ");}); Casper.then (function () { this.wait (5000,function () { this.echo ("I ' ve waited for 5 seconds Again ,pleAse input code "); }); }); casper.then (function () { This.fill (' form[id= ' fmlogin "] ', {' DeptID ': ' 320300 ', ' loginId ': ' ID number ', ' passwd ': ' Password ', ' Authcode ': Code},false);}); Casper.then (function () {This.click (". Login_buton"); This.capture ("Login.jpeg"); }); Casper.then (function () { this.wait (10000,function () { this.echo ("I ' Ve waited for 10 seconds again"); }); }); Casper.then (function () { This.echo (' new location is ' + this.getcurrenturl ()); this.capture ("Main.jpeg"); Casper.then (function) { if (this.exists ("#plan")) { if (This.exists ("#studyForm1 .btn _iskt2 span ")) { &nbsP; this.click ("#studyForm1 .btn_iskt2 span"); this.echo ("exists"); }else{ this.echo ("not exists"); } }else{ this.echo ("not exists"); }) ; Casper.then (function () { this.wait (10000,function () { this.echo ("I ' ve waited for 10 Seconds again "); }); }); Casper.then (function () { this.capture ("Video.jpeg"); }); Casper.run ();
This article is from the "Yan" blog, please be sure to keep this source http://suyanzhu.blog.51cto.com/8050189/1900433
Casperjs Demo Login-Driving School Login