[英]CasperJS - Screenshots of table rows
我從CasperJS開始,對“捕獲”功能很感興趣。 對於“練習”,我想要捕獲表的每一行,如下所示:
<table id="idTable">
<thead>
<tr id="theader">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</thead>
<tbody>
<tr class="" rel="xx">
<td>Content1</td>
<td>Content2</td>
<td>Content3</td>
</tr>
</tbody>
</table>
到目前為止,我在這里:
var casper = require('casper').create({
clientScripts: ["jquery.min.js"]
});
function createScreenshots() {
var i = 0;
$('#idTable > tbody > tr').each(function() {
this.captureSelector('myscreens/'+i+'.png', $(this).selector);
i++;
});
}
casper.start('mywebsite.com',function(){
this.evaluate(createScreenshots);
});
casper.run();
但是沒有任何效果(沒有錯誤,但«myscreens»文件夾中沒有屏幕截圖)。 如果有人可以給我指路?
提前致謝,
開23
在頁面上下文中無法訪問this.captureSelector
。 您需要在頁面上下文之外進行迭代。
casper.start('mywebsite.com',function(){
var rows = this.evaluate(function(){
return document.querySelectorAll("#idTable > tbody > tr").length;
});
for(var i = 0; i < rows; i++) {
this.captureSelector('myscreens/'+i+'.png', '#idTable > tbody > tr:nth-of-type('+i+')');
}
});
casper.run();
您的jQuery版本是什么?
你有沒有試圖打印$(本).selector
$('#idTable > tbody > tr').each(function() {
echo $(this).selector;
i++;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.