Reputation: 4017
I'm facing come difficulties with a CasperJS script.
I would like to click
on a link, the edit
one.
<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>
I tried to use the evaluate
function in the CasperJS API but it returns some [Object object] and it can't click on it.
Here is my code:
var link = casper.evaluate(function() {
return [].map.call(__utils__.findAll('tr'), function(node) {
return node.getAttribute('a');
});
});
this.click(link);
Upvotes: 0
Views: 751
Reputation: 61952
casper.click()
expects a selector (CSS3 selectors, or XPath expressions through a helper utility). You can click a single element with
casper.click("tr.myclass .edit");
If you want to click a link in a specific row, you can use the :nth-child()
selector:
casper.click("tr:nth-child(3) .edit"); // 3rd tr
Upvotes: 2