[英]CasperJS timeout while logging into a bank account
我正在尝试使用CasperJS登录到Capital One 360银行帐户。 它会加载用户名屏幕,正确输入用户名,加载密码屏幕,但随后会超时(大概没有错误),并在输入密码后停止。
有人对我在做什么错有任何想法吗?
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版本2.0.0
更新已切换到PhantomJS 1.9.8。 根据@Artjom B.建议。 现在有错误在说:“无法在不存在的选择器上调度mousedown事件:xpath选择器:// a [text()=“ Continue”]“。
尝试点击:
<a class="ada-new-win" href="javascript:void(0);" role="button" onclick="submitForm('continue'); return false;">Continue</a>
考虑到它正在等待密码输入框加载,我认为应该在那儿,但是我忘了其他东西吗?
PhantomJS 2.0.0有一个错误,即使专门侦听各种错误事件,错误也不会打印到控制台。 这就是为什么您看不到明显的错误的原因:
TypeError:true不是函数
发生该错误的原因是您将true
作为waitForSelector()
的第三个参数提供,但函数签名为
waitForSelector(String selector[, Function then, Function onTimeout, Number timeout])
脚本中的某些步骤似乎中断了,因为找不到选择器。 为onTimeout
传递的函数将被执行,但true
不是函数。 只需删除第三个参数即可查看错误所在。 如果仍然没有显示任何内容,请尝试使用PhantomJS 1.9.8。
您或者需要使用waitForSelector(x(selector))
等待“继续”按钮出现,并且/或者需要使用更强大的选择器:
var x = require("casper").selectXPath;
...
var continueButtonSelector = x("//a[contains(text(), 'Continue')]");
casper.waitForSelector(continueButtonSelector);
casper.thenClick(continueButtonSelector);
有时这是必要的,因为元素可能是用这样的空格定义的
<a> Continue </a>
^^^ ^^^
这意味着text()="Continue"
无法匹配。 浏览器渲染器无视此空白,但仍在DOM中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.