CasperJs模拟登陆人人网(新浪微博登陆有问题)

//登陆人人代码
1
var casper = require('casper').create(); 2 casper.start('http://www.renren.com', function() { 3 this.fill('form[id="loginForm"]', { 4 'email': 'XXXX@gmail.com', 5 'password': '********' 6 }, false); 7 }); 8 9 casper.then(function() { 10 this.click('input[class="input-submit login-btn"]'); 11 12 this.echo('clicked...'); 13 }); 14 15 casper.then(function() { 16 this.echo(this.getTitle()); 17 }); 18 casper.run();

截图如下:

 

登陆新浪微博却提示找不到对应name,代码如下:

 1 var casper = require('casper').create();  
 2   
 3   
 4 casper.start('http://www.weibo.com/', function() {  
 5         this.test.assertExists('div[class="inp username"]', 'div[class="inp username"] is found');  
 6         this.test.assertExists('div[class="inp password"]', 'div[class="inp password"] is found');  
 7         this.test.assertExists('a[class="W_btn_g"]', 'submit button is found');  
 8         this.echo("inputs of name and pass both exists.");  
 9         this.echo('name=' + this.fetchText('input[class="name'));  
10         this.echo('pass=' + this.fetchText('input[class="pass"]'));  
11   
12         this.echo('first location is ' + this.getCurrentUrl());  
13         this.capture("login.png");  
14         }  
15 );  
16   
17 casper.then(function() {  
18         this.wait(10000,function() {  
19                 this.echo("I've waited for 10 seconds");  
20         });  
21 });  
22   
23 casper.then(function() {  
24         this.fill('div[class="inp username"]', {'username':'%%%%@sina.com'}, false);  
25         this.fill('div[class="inp password"]', {'password':'!!!???'}, false);  
26         this.click('a[class="W_btn_g"]');  
27         this.echo('clicked...');  
28 });  
29   
30 casper.then(function() {  
31         this.wait(10000,function() {  
32                 this.echo("I've waited for 10 seconds again");  
33         });  
34 });  
35   
36 casper.then(function() {  
37         this.echo('new location is ' + this.getCurrentUrl());  
38         this.capture("logined.png");  
39 });  
40   
41   
42 casper.run();

 

 

posted @ 2013-02-25 12:29  donkra  阅读(2266)  评论(4编辑  收藏  举报