CasperJS/PhantomJS在加载页面时感到窒息 [英] CasperJS/PhantomJS chokes on loading a page
问题描述
我正在使用phantomjs运行以下脚本:
I'm running the following script with 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,以允许用户登录.
Until a few days ago I could access the page which loads an iframe that contains 2 form fields, to allow user login.
现在出现以下错误:
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并在加载页面时遇到问题的问题.我该如何解决?
The page loads fine using slimerjs as the engine, but when using slimerjs the login form does not get filled in because the window is not in focus. I believe this is an issue where casper is using an old version of WebKit and chokes on loading the page. How would I fix this?
推荐答案
解决问题为时已晚,但如果有人在PhantomJS中找到搜索startsWith
问题的问题,则可能对以后的参考很有用(就像我所做的那样):在ECMAScript上添加了 startsWith
方法6规范,PhantomJS不支持.
Too late to solve the problem but maybe useful for future reference if somebody finds the question searching for a problem with startsWith
in PhantomJS (as I did): startsWith
method was added on the ECMAScript 6 specification, which is not supported by PhantomJS.
为此的一个很好的填充是 mathiasbynens/String.prototype.startsWith
A good polyfill for this is mathiasbynens/String.prototype.startsWith
这篇关于CasperJS/PhantomJS在加载页面时感到窒息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!