我用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并在加载页面时窒息.我该如何解决这个问题?
如果有人发现startsWith
在PhantomJS中搜索问题的问题(如我所做),解决问题的时间太晚,但可能对将来参考有用:startsWith
在ECMAScript 6规范中添加了方法,PhantomJS不支持该方法.
一个很好的polyfill是mathiasbynens/String.prototype.startsWith