我面临CasperJS脚本的困难。
我想在click
链接edit
上<div class="list">
<table>
<thead>
<tr>
<th width="5%">State</th>
<th width="5%">State1</th>
....
</tr>
</thead>
<tbody>
<tr class="myclass">
<td class="center"><a href="viewer.php?file=1902440_14313152"><img src="img/picto/picto.png"/></a></td>
...
<td class="center actions">
<div class='relative'>
<a href="#" class="info"><img src="img/info.png"/></a>
<a class="edit" href="viewer.php?file=19095CFBCD260702440_14313152"><img src="img/picto/picto.png"/></a>
。
evaluate
我尝试在CasperJS API中使用var link = casper.evaluate(function() {
return [].map.call(__utils__.findAll('tr'), function(node) {
return node.getAttribute('a');
});
});
this.click(link);
函数但它返回一些[Object object]并且无法点击它。
这是我的代码:
{{1}}
答案 0 :(得分:2)
casper.click()
需要一个选择器(CSS3选择器,或通过辅助工具实现的XPath表达式)。您可以使用
casper.click("tr.myclass .edit");
如果要点击特定行中的链接,可以使用:nth-child()
选择器:
casper.click("tr:nth-child(3) .edit"); // 3rd tr