input
元素不具有name
属性,所以我必须使用的input
元素。本来我用这个代码:如何使用CasperJS中的输入ID登录表单?
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);
});
也不起作用。 FYI:
# phantomjs --version
1.9.7
# casperjs --version
1.1.0-beta3
运行报告:
[email protected]:/var/www/casperjs-phantomjs# casperjs test.js [email protected] 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 [email protected]
[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/
你点击提交按钮试试? – Fanch
@Fanch是的,当然。但如果你的意思是使用CasperJS点击,我不是。顺便说一下,如何做到这一点? – Phoenix
是的,CasperJS点击,看到[casperjs填充和单击不工作,因为我预期不能单击按钮](http://stackoverflow.com/questions/22516182/casperjs-fill-and-click-not-working-asi-i-预计,不能点击按钮/ 22527446#22527446) – Fanch