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

xiaoxiao2021-03-01  10

文章结束给大家来个程序员笑话:[M]

//登岸人人代码 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();

 

 

文章结束给大家分享下程序员的一些笑话语录: 警告 有一个小伙子在一个办公大楼的门口抽着烟,一个妇女路过他身边,并对他 说, “你知道不知道这个东西会危害你的健康?我是说, 你有没有注意到香烟 盒上的那个警告(Warning)?” 小伙子说,“没事儿,我是一个程序员”。 那妇女说,“这又怎样?” 程序员说,“我们从来不关心 Warning,只关心 Error”

转载请注明原文地址: https://www.6miu.com/read-3350138.html

最新回复(0)