简体   繁体   English

登录银行帐户时CasperJS超时

[英]CasperJS timeout while logging into a bank account

I'm attempting to login to a Capital One 360 bank account using CasperJS. 我正在尝试使用CasperJS登录到Capital One 360​​银行帐户。 It loads the username screen, properly enters a username, loads the password screen, but then times-out (presumably, there's no error) and stops after entering the password. 它会加载用户名屏幕,正确输入用户名,加载密码屏幕,但随后会超时(大概没有错误),并在输入密码后停止。

Anyone have any ideas as to what I'm doing wrong? 有人对我在做什么错有任何想法吗?

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug"
});

var capone360 = "https://secure.capitalone360.com/myaccount/banking/login.vm";

casper.start(capone360);

casper.then(function(){
   casper.waitForSelector("#ACNID", function() {
        this.echo(this.getTitle());
        this.sendKeys('#ACNID', username);
    }, true); 
});

casper.then(function(){
    this.click("#btn_continue"); 
});

casper.then(function(){
    this.waitForSelector("#currentPassword_TLNPI", function() {
        this.echo(this.getTitle());
        this.sendKeys('#currentPassword_TLNPI', password);
    }, true);
});

casper.then(function(){
    this.clickLabel("Continue", "a");
});

casper.then(function(){
    this.waitForSelector("#deposittable", function() {
        this.echo(this.getTitle());
    }, true);
});

casper.run();

PhantomJS version 2.0.0 PhantomJS版本2.0.0

Update Switched to PhantomJS 1.9.8. 更新已切换到PhantomJS 1.9.8。 per @Artjom B. suggestion. 根据@Artjom B.建议。 Now there are errors saying: 'Cannot dispatch mousedown event on nonexistent selector: xpath selector: //a[text()="Continue"]'. 现在有错误在说:“无法在不存在的选择器上调度mousedown事件:xpath选择器:// a [text()=“ Continue”]“。

It's attempting to click: 尝试点击:

<a class="ada-new-win" href="javascript:void(0);" role="button" onclick="submitForm('continue'); return false;">Continue</a>

I assumed it should be there given that it's waited for the password input box to load, but am I forgetting something else? 考虑到它正在等待密码输入框加载,我认为应该在那儿,但是我忘了其他东西吗?

PhantomJS 2.0.0 has a bug where errors are not printed to the console even when specifically listening to the various error events. PhantomJS 2.0.0有一个错误,即使专门侦听各种错误事件,错误也不会打印到控制台。 That is why you don't see the obvious error which would go something like this: 这就是为什么您看不到明显的错误的原因:

TypeError: true is not a function TypeError:true不是函数

The reason for that error is that you're providing true as a third parameter for waitForSelector() , but the function signature is 发生该错误的原因是您将true作为waitForSelector()的第三个参数提供,但函数签名为

waitForSelector(String selector[, Function then, Function onTimeout, Number timeout])

It seems that some step in your script breaks, because a selector cannot be found. 脚本中的某些步骤似乎中断了,因为找不到选择器。 The passed function for onTimeout will be executed, but true is not a function. onTimeout传递的函数将被执行,但true不是函数。 Simply remove the third parameter to see where the error lies. 只需删除第三个参数即可查看错误所在。 If still nothing is shown, try using PhantomJS 1.9.8. 如果仍然没有显示任何内容,请尝试使用PhantomJS 1.9.8。


You either need to wait for the "Continue" button to appear using waitForSelector(x(selector)) and/or you need to use a more robust selector: 您或者需要使用waitForSelector(x(selector))等待“继续”按钮出现,并且/或者需要使用更强大的选择器:

var x = require("casper").selectXPath;
...
var continueButtonSelector = x("//a[contains(text(), 'Continue')]");
casper.waitForSelector(continueButtonSelector);
casper.thenClick(continueButtonSelector);

This is sometimes necessary, because the element is probably defined with whitespace like this 有时这是必要的,因为元素可能是用这样的空格定义的

<a>   Continue   </a>
   ^^^        ^^^

which means that text()="Continue" cannot match. 这意味着text()="Continue"无法匹配。 The browser renderer disregards this whitespace, but it is still in the DOM. 浏览器渲染器无视此空白,但仍在DOM中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM