[英]Clicking to next page on casperjs not working
I am trying to take a screenshot of the second page on a website that uses ajax, using casperjs. 我正在尝试使用casperjs在使用ajax的网站上截取第二页的屏幕截图。 I used Chrome and Ressurectio to create a test script and changed it slightly in order to suit my needs. 我使用Chrome和Ressurectio创建了一个测试脚本,并对其进行了一些改动以适应我的需求。
However, when I run the script, the second screenshot only shows the "loading" page, which at first I thought it's due to ajax being slow... 但是,当我运行脚本时,第二张屏幕截图仅显示“正在加载”页面,起初我认为这是由于Ajax运行缓慢而引起的...
The problem is that even with a timeout of 15 seconds, it still doesn't take the screenshot that I want. 问题在于,即使超时时间为15秒,它仍然无法获取我想要的屏幕截图。
Maybe I'm forgetting something? 也许我忘记了什么?
Here's my script: 这是我的脚本:
var x = require('casper').selectXPath;
casper.options.viewportSize = {width: 1366, height: 667};
casper.on('page.error', function(msg, trace) {
this.echo('Error: ' + msg, 'ERROR');
for(var i=0; i<trace.length; i++) {
var step = trace[i];
this.echo(' ' + step.file + ' (line ' + step.line + ')', 'ERROR');
}
});
casper.test.begin('Resurrectio test', function(test) {
casper.start('http://recrutamento.auchan.pt/listaofertas.aspx');
casper.waitForSelector(x("//a[normalize-space(text())='>>>']"),
function success() {
this.capture('click1.png')
test.assertExists(x("//a[normalize-space(text())='>>>']"));
this.click(x("//a[normalize-space(text())='>>>']"));
this.wait(7000);
this.capture('click2.png')
},
function fail() {
test.assertExists(x("//a[normalize-space(text())='>>>']"));
});
casper.run(function() {test.done();});
});
wait
is an asynchronous step function such as then
, so you have to put capture
into the callback of wait
: wait
是then
wait
异步步骤函数,因此您必须将capture
放入wait
的回调中:
this.wait(7000, function(){
this.capture('click2.png')
});
You're taking the screenshot to early. 您正在将屏幕截图提前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.