How to login in the form using input id in CasperJS?

帖子列表 发布于 2014/05/13 18:18
阅读 365
收藏 0

The input element don't have name attribute, so I have to use id of input element. Originally I used this code:

casper.start('https://mp.weixin.qq.com/', function() { 
    this.fillSelectors('form#login-form', { 
        'input[id="account"]':  usr, 
        'input[id="password"]': passwd 
    }, true); 
});

Just won't work, so I tried fillXPath(),

casper.start('https://mp.weixin.qq.com/', function() { 
    this.fillXPath('form#login-form', { 
        '//input[@id="account"]':  usr, 
        '//input[@id="password"]': passwd 
    }, true); 
});

Also not work. FYI:

 # phantomjs --version
 1.9.7
 # casperjs --version
 1.1.0-beta3

Running report:

root@do1:/var/www/casperjs-phantomjs# casperjs test.js aaaaa@qq.com mysecret
[info] [phantom] Starting...
[info] [phantom] Running suite: 3 steps
[debug] [phantom] opening url: https://mp.weixin.qq.com/, HTTP GET
[debug] [phantom] Navigation requested: url=https://mp.weixin.qq.com/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://mp.weixin.qq.com/"
[debug] [phantom] Automatically injected ./jquery-1.11.1.min.js client side
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/3 https://mp.weixin.qq.com/ (HTTP 200)
[info] [remote] attempting to fetch form element from selector: 'form#login-form'
[debug] [remote] Set "null" field value to aaaaa@qq.com
[debug] [remote] Set "null" field value to *******
[info] [remote] submitting form to unknown, HTTP GET
[info] [phantom] Step anonymous 2/3: done in 970ms.
[debug] [phantom] Navigation requested: url=https://mp.weixin.qq.com/?, type=FormSubmitted, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://mp.weixin.qq.com/?"
[debug] [phantom] Automatically injected ./jquery-1.11.1.min.js client side
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 3/3 https://mp.weixin.qq.com/? (HTTP 200)
Page url is https://mp.weixin.qq.com/?
Page title is 公众平台登录
[info] [phantom] Step anonymous 3/3: done in 1532ms.
[info] [phantom] Done 3 steps in 1549ms



加载中
0
帖子列表
帖子列表
@红薯        大神帮我看看纳
返回顶部
顶部