无法使用CasperJS提交表单-换句话说,无法登录 [英] Cannot submit form with CasperJS - in other words cannot login

查看:110
本文介绍了无法使用CasperJS提交表单-换句话说,无法登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用方法 start fill waitForUrl ,但无法执行此操作。 在我看来,表单尚未提交,因为 waitForUr 的超时每次都过期。

I'm trying to login into Tumblr with CasperJS using methods start, fill and waitForUrl but cannot do this. It seems to me that form wasn't submitted, because timeout in waitForUr expired everytime.

终端响应:

Terminal response:

我正在使用的代码是:

/*jslint browser: true, regexp: true */
// global casper, require 

var LOGIN_URL, LOGIN_USERNAME, LOGIN_PASSWORD, casper;

casper = require('casper').create({
    waitTimeout: 20000,
    viewportSize: {
        width: 1024,
        height: 768
    },
    verbose: true,
    logLevel: 'debug',
    userAgent: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'
});

if (!casper.cli.has('username') && !casper.cli.has('password')) {
    casper.echo('Usage: $ casperjs sfdclogin.casper.js --username=USERNAME --password=PASSWORD').exit(-1);
}

LOGIN_URL = 'https://tumblr.com/login';

LOGIN_USERNAME = casper.cli.get('username');
LOGIN_PASSWORD = casper.cli.get('password');

phantom.cookiesEnabled = true;

casper
    .start(LOGIN_URL, function () {
        // 'use strict';

        this.log('Logging in', 'debug');
        /*
        this.fillSelectors('#signup_form_form', {
            '#signup_email': LOGIN_USERNAME,
            '#signup_password': LOGIN_PASSWORD
        }, true);
        */

        this.fill('#signup_form_form', {
            '#user[email]': LOGIN_USERNAME,
            '#user[password]': LOGIN_PASSWORD
        }, true);
    })

    .waitForUrl('http://tumblr.com/dashboard', function () {
        // 'use strict';

        this.echo('We\'re logged in.');
    })

    .run();

,我在此脚本中使用了正确的用户名和密码。

Also, I'm using correct username and password with this script.

推荐答案

尝试使用以下内容代替当前的 casper.fill ()
这是因为CasperJS的 fill()搜索元素的名称属性。

Try using the following instead of your current casper.fill(). This is because CasperJS' fill() searches for the name attribute of elements.

this.fill('#signup_form', {
    'user[email]': LOGIN_USERNAME,
    'user[password]': LOGIN_PASSWORD
}, true);

如果您想继续使用id作为选择器,可以使用它。

You could use this if you want to continue using the ids as selectors.

this.fillSelectors('#signup_form', {
    '#signup_email': LOGIN_USERNAME,
    '#signup_password': LOGIN_PASSWORD
}, true);

这篇关于无法使用CasperJS提交表单-换句话说,无法登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆