Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda