我使用了以下链接中的代码登录..它可以正常使用facebook .. How to login into a website with CasperJS?
但它为我网站的登录页面提供了错误。 username字段的名称是LoginForm [username]和 密码字段的名称是LoginForm [密码]。
我的代码。
casper.start(url, function() {
// search for 'casperjs' from google form
console.log("page loaded");
this.test.assertExists('form#login-form', 'form is found');
this.fill('form#login-form', {
LoginForm[username]: 'ascd@csc.com',
LoginForm[password]: '******'
}, true);
});
输出
[info] [remote] attempting to fetch form element from selector: 'form#login-form'
remote message caught: attempting to fetch form element from selector: 'form#login-form'
[error] [remote] TypeError: 'undefined' is not an object (evaluating 'field.getAttribute')
remote message caught: TypeError: 'undefined' is not an object (evaluating 'field.getAttribute')
Page Error: TypeError: 'undefined' is not an object (evaluating 'field.getAttribute')
FAIL CasperError: Unable to fill form
# type: uncaughtError
# error: "CasperError: Unable to fill form"
CasperError: Unable to fill form
//// HTML
答案 0 :(得分:0)
this.fill('form#login-form', {
'LoginForm[username]': 'ascd@csc.com',
'LoginForm[password]': '******'
}, true);