input元素没有name属性,所以我必须使用id of input元素。我最初使用的代码是:
casper.start('https://mp.weixin.qq.com/', function() {
this.fillSelectors('form#login-form', {
'input[id="account"]': usr,
'input[id="password"]': passwd
}, true);
});就是不管用所以我试过fillXPath()
casper.start('https://mp.weixin.qq.com/', function() {
this.fillXPath('form#login-form', {
'//input[@id="account"]': usr,
'//input[@id="password"]': passwd
}, true);
});也不能工作。仅供参考:
# phantomjs --version
1.9.7
# casperjs --version
1.1.0-beta3运行报告:
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登录页面为:https://mp.weixin.qq.com/
发布于 2014-05-14 05:09:13
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"]');
});发布于 2014-11-08 19:42:23
将函数选择器用于casper.fillSelectors http://www.w3.org/TR/css3-selectors/#id-selectors函数(‘https://mp.weixin.qq.com/’,css3 (){
this.fillSelectors('form#login-form', {
'#account': usr,
'#password': passwd
}, true);
});https://stackoverflow.com/questions/23627875
复制相似问题