CasperJS version 1.1.0-beta3
casper.start(someLink);
function getUrl(link) {
casper.thenOpen(basePath + link);
casper.then(function() {
var par1 = this.fetchText('body > table > tbody > tr > td > div > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) > td > table > tbody > tr:nth-child(4) > td:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(2) > strong > span')
this.echo(par1);
var par2 = this.fetchText('body > table > tbody > tr > td > div > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) > td > table > tbody > tr:nth-child(4) > td:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(3) > strong > span')
this.echo(par2);
});
}
getUrl(someRelativeUrl);
casper.run(function() {
this.echo('DONE!');
});
Problem: par1 displays the right value, par2 is empty. I change their order, placing par2 before par1: in this case, par2 displays right and par1 is empty.
What am I doing wrong? Obviously, the fetchText lines are correct, and the CSS are correct, yet only the first one fetches: the next ones all remain empty.
Edit: Here's the actual html that gives the problems (stackoverflow somehow hides the section and the DOCTYPE from the code). As simple as it gets: Details
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">
<table width="1000" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="1000" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="217" valign="top" bgcolor="#E3E5E4"><table width="100%" border="0" cellspacing="0" cellpadding="0">
</table></td>
<td width="783" align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right" bgcolor="#D4D6D5"><img src="top.jpg" width="180" height="179" /></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="3%"> </td>
<td width="97%"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="2%"> </td>
<td width="49%"align="left" class="style10">POLE1: <strong><span class="style7">ADR1 </span></strong></td>
<td width="49%"align="left" class="style10">POLE2: <strong><span class="style7">ADR2 </span></strong></td>
</tr>
<tr>
</table></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor="#170E13"> </td>
</tr>
</table>
</div></td>
</tr>
</table>
</body>
</html>
Thanks!