[英]How to login in the form using input id in CasperJS?
The input
element don't have name
attribute, so I have to use id
of input
element. input
元素没有name
属性,因此我必须使用input
元素的id
。 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()
, 只是行不通,所以我尝试了
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
Login page is : https://mp.weixin.qq.com/
登录页面是:
https://mp.weixin.qq.com/
: https://mp.weixin.qq.com/
fillSelectors should work fine, but you might use sendKeys and click as a workaround: fillSelectors应该可以正常工作,但是您可以使用sendKeys并单击作为一种解决方法:
casper.start('https://mp.weixin.qq.com/', function() {
this.sendKeys('input[id="account"]', "my_account");
this.sendKeys('input[id="password"]', "my_password");
this.click('input[type="submit"]');
});
Use css3 selectors for casper.fillSelectors http://www.w3.org/TR/css3-selectors/#id-selectors casper.start(' https://mp.weixin.qq.com/ ', function() { 为casper.fillSelectors使用css3选择器http://www.w3.org/TR/css3-selectors/#id-selectors casper.start(' https://mp.weixin.qq.com/',function (){
this.fillSelectors('form#login-form', {
'#account': usr,
'#password': passwd
}, true);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.