当前位置:  开发笔记 > 编程语言 > 正文

CasperJS/PhantomJS在加载页面时窒息

如何解决《CasperJS/PhantomJS在加载页面时窒息》经验,为你挑选了1个好方法。

我用phantomjs运行以下脚本:

var casper = require('casper').create();
var url = 'https://itunesconnect.apple.com/itc/static/login?view=1&path=%2FWebObjects%2FiTunesConnect.woa%3F'

casper.on("page.error", function(msg, trace) {
  this.echo("Error:    " + msg, "ERROR");
  this.echo("file:     " + trace[0].file, "WARNING");
  this.echo("line:     " + trace[0].line, "WARNING");
  this.echo("function: " + trace[0]["function"], "WARNING");
  errors.push(msg);
});



casper.start(url, function(){
    casper.wait(7000, function(){
        // casper.echo(casper.getHTML());
    })
})

casper.run(function() {
  if (errors.length > 0) {
    this.echo(errors.length + ' Javascript errors found', "WARNING");
  } else {
    this.echo(errors.length + ' Javascript errors found', "INFO");
  }
  casper.exit();
});

直到几天前,我才能访问加载包含2个表单字段的iframe的页面,以允许用户登录.

现在我收到以下错误:

Error:    Error: undefined is not a constructor (evaluating '$stateParams.path.startsWith('/')')

    at setupDSiFrame (https://itunesconnect.apple.com/itc/static-resources/controllers/login_cntrl.js?cache=111920151100:99:46)

    at https://itunesconnect.apple.com/itc/static-resources/controllers/login_cntrl.js?cache=111920151100:19:37

    at $digest (https://itunesconnect.apple.com/itc/js/compiled/lib/vendor.js?cache=111920151100:13:11750)

    at $apply (https://itunesconnect.apple.com/itc/js/compiled/lib/vendor.js?cache=111920151100:13:13237)

    at f (https://itunesconnect.apple.com/itc/js/compiled/lib/vendor.js?cache=111920151100:12:56414)

    at r (https://itunesconnect.apple.com/itc/js/compiled/lib/vendor.js?cache=111920151100:12:65848)

    at onreadystatechange (https://itunesconnect.apple.com/itc/js/compiled/lib/vendor.js?cache=111920151100:12:66409)

file:     https://itunesconnect.apple.com/itc/js/compiled/lib/vendor.js?cache=111920151100

line:     12

使用slimerjs作为引擎加载页面很好,但是当使用slimerjs时,登录表单不会被填充,因为窗口不在焦点上.我相信这是一个问题,其中casper使用旧版本的WebKit并在加载页面时窒息.我该如何解决这个问题?



1> Patricia Gar..:

如果有人发现startsWith在PhantomJS中搜索问题的问题(如我所做),解决问题的时间太晚,但可能对将来参考有用:startsWith在ECMAScript 6规范中添加了方法,PhantomJS不支持该方法.

一个很好的polyfill是mathiasbynens/String.prototype.startsWith

推荐阅读
ERIK又
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有