Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Casper JS returns only first row of a table

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!