I have a table as below:
<table id="securedTable" border="1" cellspacing="0" cellpadding="1" class="secured">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>Lien Number</th>
<th>Lien Type</th>
<th>Filed</th>
<th>Terminate Date</th>
<th>Lapse Date</th>
</tr>
</thead>
<tbody>
<tr class="oddRow">
<td class="borderedTd"><a href="javascript:generateFileNumberSearchResult(92919403)">XXXXXXXX</a></td>
<td class="borderedTd">PO BOX 2576</td>
</tr>
<tr class="evenRow">
<td class="borderedTd"><a href="javascript:generateFileNumberSearchResult(92919732)">YYYYYYYYYY</a></td>
<td class="borderedTd">PO BOX 2576</td>
</tr>
.
.
.
.
</tbody>
</table>
I'm trying to get the href of every link inside the first td of every tr of the table. My casperJS code is as below:
casper.waitForSelector('input[id="nonStandardSearchFormID_0"], input[value="Search"]', function () {
this.click('input[id="nonStandardSearchFormID_0"], input[value="Search"]');
logMsg('Form submitted.');
});
casper.waitForSelector('form[name="resultsDisplayFormID"]', function () {
if (this.exists('form[name="resultsDisplayFormID"]')) {
logMsg("Data loaded.");
} else {
logMsg('No data loaded.');
}
});
casper.then(function () {
var rows = this.evaluate(function () {
return document.querySelectorAll('#securedTable tbody tr td:first-child');
});
var length = rows.length;
logMsg("table length: " + length);
for (var i = 0; i < length; i++) {
logMsg(JSON.stringify(rows[i].children[0].href));
}
});
casper.run();
The code works and I see that the total number or rows is 54 which is correct however, it seems like only the first table row href is extracted because the error I get is this:
table length: 54
"javascript:generateFileNumberSearchResult(92919403)"
TypeError: null is not an object (evaluating 'rows[i].children')
Any help please? Thanks.