0

I want to verify that i have a trafic in my box. So i want to check that "Total" is different de 0 but i fail.

http://clip2net.com/s/54bx8J

HTML code :

<span>
<table>
<tbody>
<tr>
<td class="left">Upload</td>
<td class="right">276 KB</td>
</tr>
<tr>
<td class="left">Download</td>
<td class="right">661 KB</td>
</tr>
<tr>
<td class="left">Total</td>
<td class="right">937 KB</td>
</tr>
<tr>
<td class="left">Duration</td>
<td class="right">5min19s</td>
</tr>
</tbody>
</table>
</span>

And my script :

  WebElement data = (driver.findElement(By.xpath("//tr[@class='right' and text()[contains(., 'Download')]/td[2]")));
         System.out.println(data);
    Thread.sleep(3000);

assertTrue(data != null);

Thanks

Julien P.
  • 91
  • 1
  • 2
  • 8

1 Answers1

0

You should not try to print the WebElement. Instead, try to access its data by calling getAttribute or getText, depending on the type of element you are selecting.

See http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebElement.html for the WebElement spec.

Also, it would be helpful if you post the html source that you are trying to select/parse.

Farlan
  • 1,860
  • 2
  • 28
  • 37
  • Thanks for your help T want to check that "Total" is different to 0 937 KB – Julien P. May 15 '13 at 13:34
  • calling getText() on your WebElement should return a String with "937 KB" – Farlan May 15 '13 at 13:37
  • I just used getText() it's a good idea but i have a problem to récuperate the number (927 ) and check which it's different to 0. String data = (driver.findElement(By.xpath("//tr[@class='right' and text()[contains(., 'Download')]/td[2]"))).getText(); System.out.println(data); – Julien P. May 15 '13 at 13:46
  • once you have the value, all you need to do is parse the integer out of the string. For ideas on how to do that, check out http://stackoverflow.com/questions/5585779/how-to-convert-string-to-int-in-java – Farlan May 15 '13 at 14:04
  • I managed to retrieve the value, but I want to remove the 'MB' but substring () to remove it before it except that I want to delete the following numbers – Julien P. May 15 '13 at 14:10