root@krusty:/www/site.com# casperjs ./amazon_login.js
Title: Amazon Sign In
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
Segmentation fault (core dumped)
root@krusty:/www/site.com#
我无法弄清楚原因。这里有人知道这个吗?我不知道还有什么要输入,但这就是说我必须在我显示的代码片段中添加更多文字批量,所以这就是我所做的:我&#39;我在谷歌搜索了这次崩溃的文本,发现我必须导出一个特定的QT变量,所以我也这样做了,它在执行phantomjs时稍微进行了一些脚本功能,但仍然崩溃。
如果我是专门从幻影&#39;幻影&#39;并取消注释下面写的脚本代码的前几行我得到这个输出:
root@krusty:/www/nuper.com# /root/phantomjs-2.1.1-linux-x86_64/bin/phantomjs ./amazon_login.js
Title: Amazon Sign In
Capping
Done
FAIL TypeError: undefined is not a function (evaluating 'casper.done()')
# type: uncaughtError
# error: undefined is not a function (evaluating 'casper.done()')
# phantomjs://code/amazon_login.js:54:16
# checkStep@phantomjs://platform/casper.js:423:28
# stack: not provided
PASS Untitled suite in null
phantomjs访问的amazon_login.js中的代码:
//phantom.casperPath = '/root/node_modules/casperjs';
//phantom.injectJs('/root/node_modules/casperjs/bin/bootstrap.js');
// if you need the test environment then you need this
//phantom.casperTest = true;
var casper = require('casper').create();
casper.userAgent('Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0');
phantom.cookiesEnabled = true;
var AMAZON_USER = '<removed>';
var AMAZON_PASS = '<removed>';
casper.start('https://www.amazon.com/').thenClick('a#nav-link-accountList',
function() {
this.echo('Title: ' + this.getTitle());
var emailInput = 'input#ap_email';
var passInput = 'input#ap_password';
this.mouseEvent('click', emailInput, '15%', '48%');
this.sendKeys('input#ap_email', AMAZON_USER);
this.wait(3000, function() {
this.mouseEvent('click', passInput, '12%', '67%');
this.sendKeys('input#ap_password', AMAZON_PASS);
this.mouseEvent('click', 'input#signInSubmit', '50%', '50%');
});
});
casper.then(function(e) {
this.wait(5000, function() {
this.echo('Capping');
this.capture('amazon.png');
});
});
/* casper.thenOpen('https://www.amazon.com/ss/help/contact/?_encoding=UTF8&marketplaceID=ATVPDKIKX0DER&ref_=v_sp_contact_seller&sellerID=A39LA0PG14JNN7',
function() {
this.echo('Second Page: ' + this.getTitle());
this.wait(3000, function() {
this.mouseEvent('click', 'span#a-autoid-7', '12%', '67%');
this.mouseEvent('click', 'a#preOrderSubject_0', '12%', '67%');
this.mouseEvent('click', 'input#a-button-input', '50%', '50%');
this.echo('Title: ' + this.getTitle());
});
});
*/
casper.run(function() {
console.log('Done');
casper.done();
});
答案 0 :(得分:0)
您在最后一行中有.done
方法,并且您在Casper对象而不是测试对象上调用它。完成方法是Casper中Tester模块的方法,你在没有Tester模块的情况下调用你的casper。
根据您在第一种情况下的代码中断,我建议您倾听所有错误事件,例如page.error
,resource.error
......
希望有所帮助!