Using selenium i'm trying to read out a dynamically generated table, i got down to the right elements (using the findElement
method) but using getText()
on them returns nothing.
Probably because getText()
looks for quotation marks when returning text and can't find any between the <td>
tags. Some suggestions were to use xpaths but since the tables are generated dynamically the location of the value i need also changes.
here's the table i'm trying to get 3 data points from:
<table cellpadding=0 cellspacing=0 class=fleetinfo>
<tbody><tr>
<th colspan=2>Schepen:</th>
</tr>
<tr>
<td>Groot vrachtschip:</td>
<td class=value>
40 </td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<th colspan=2>Lading:</th>
</tr>
<tr>
<td>Metaal:</td>
<td class=value>
536.062 </td>
</tr>
<tr>
<td>Kristal:</td>
<td class=value>
289.008 </td>
</tr>
<tr>
<td>Deuterium:</td>
<td class=value>
92.750 </td>
</tr>
</tbody></table>
the ones i'm interested in are the ones inside the <td class=value>
tags but as i said before, using getText()
on them returns null.
Any idea on how i can acces those values?
edit: here's how i'm doing it now
private int getMetalFromFleet(WebElement fleet)
{
int ret=0;
WebElement streak = fleet.findElement(By.className(starStreak));
List<WebElement>fleetDetails = streak.findElements(By.tagName(tr));
for(WebElement detail : fleetDetails)
{
List<WebElement> tabel = detail.findElements(By.tagName(td));
if(tabel.size() != 2)
continue;
if(tabel.get(0).getText().equalsIgnoreCase(metaal:))
{
ret = Integer.parseInt(tabel.get(1).getText());
break;
}
}
return ret;
}
edit: here's the relevant bit of html
<div id=fleet9965869 class=fleetDetails detailsOpened data-mission-type=4 data-return-flight=false data-arrival-time=1378241688>
<span class=timer tooltip title=03.09.2013 22:54:48 id=timer_9965869>58m 48s</span>
<span class=absTime>22:54:48 Klok</span>
<span class=mission neutral textBeefy>Plaatsen</span>
<span class=allianceName></span>
<span class=originData>
<span class=originCoords tooltip title=killernerd><a href=http://uni107.ogame.nl/game/index.php?page=galaxy&galaxy=5&system=213>[5:213:8]</a></span>
<span class=originPlanet>
<figure class=planetIcon planet tooltip js_hideTipOnMobile title=planeet></figure>k7 </span>
</span>
<span class=marker01></span>
<span class=marker02></span>
<span class=fleetDetailButton>
<a href=#bl9965869 rel=bl9965869 title=Vlootdetails class=tooltipRel tooltipClose fleet_icon_forward>
</a>
</span>
<span class=reversal reversal_time ref=9965869>
<a class=icon_link tooltipHTML href=http://uni107.ogame.nl/game/index.php?page=movement&return=9965869 title=Roep terug:| 04.09.2013<br>01:54:05>
<img src=http://gf2.geo.gfsrv.net/cdna2/89624964d4b06356842188dba05b1b.gif height=16 width=16>
</a>
</span>
<span class=starStreak>
<div style=position: relative;>
<div class=origin fixed>
<img class=tooltipHTML height=30 width=30 src=http://gf1.geo.gfsrv.net/cdnf0/af41c52dc08208b4463f4a4608e88c.png title= alt=>
</div>
<div class=route fixed>
<a href=#bl9965869 rel=bl9965869 title=Vlootdetails class=tooltipRel tooltipClose basic2 fleet_icon_forward id=route_9965869 style=margin-left: 220px;></a>
<div style=display:none; id=bl9965869>
<div class=htmlTooltip>
<h1>Vlootdetails:</h1>
<div class=splitLine></div>
<table cellpadding=0 cellspacing=0 class=fleetinfo>
<tbody><tr>
<th colspan=2>Schepen:</th>
</tr>
<tr>
<td>Groot vrachtschip:</td>
<td class=value>
960 </td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<th colspan=2>Lading:</th>
</tr>
<tr>
<td>Metaal:</td>
<td class=value>
8.173.484 </td>
</tr>
<tr>
<td>Kristal:</td>
<td class=value>
6.325.966 </td>
</tr>
<tr>
<td>Deuterium:</td>
<td class=value>
7.474.821 </td>
</tr>
</tbody></table>
</div> </div>
</div>
<div class=destination fixed>
<img class=tooltipHTML height=30 width=30 src=http://gf2.geo.gfsrv.net/cdnaa/af0b356fdbecc1cfc47130e990fa66.png title=Aankomsttijd:| 03.09.2013<br>22:54:48 alt=>
</div>
</div>
</span><!-- Starstreak -->
<span class=destinationData>
<span class=destinationPlanet>
<span>
<figure class=planetIcon planet tooltip js_hideTipOnMobile title=planeet></figure>Hoelbrak </span>
</span>
<span class=destinationCoords tooltip title=killernerd><a href=http://uni107.ogame.nl/game/index.php?page=galaxy&galaxy=1&system=2>[1:2:6]</a></span>
</span>
<span class=nextTimer tooltip title=04.09.2013 03:52:31 id=timerNext_9965869>5u 56m 31s</span>
<span class=nextabsTime>03:52:31 Klok</span>
<span class=nextMission friendly textBeefy>Keer terug</span>
<span class=openDetails>
<a href=javascript:void(0); class=openCloseDetails data-mission-id=9965869 data-end-time=1378241688>
<img src=http://gf3.geo.gfsrv.net/cdnb6/577565fadab7780b0997a76d0dca9b.gif height=16 width=16>
</a>
</span>
</div>
the values i need are the numeric values under Metaal, kristal and deuterium.