Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to count number of td/tr in a table with Robot Framework using Selenium2Library

I am using Robot Framework to automatically check the number of TDs or TRs in a table.

I am using Get Matching XPath Count keyword from Selenium, however, it always fails with an error.

My sample HTML structure:

<table id="myTable">
  <tr>
      <td style="width: 50%">my td</td>
      <td style="width: 50%">my td</td>
  </tr>
<tr>
      <td style="width: 50%">my td</td>
      <td style="width: 50%">my td</td>
  </tr>
<tr>
      <td style="width: 50%">my td</td>
      <td style="width: 50%">my td</td>
  </tr>
<tr>
      <td>Search me</td>
      <td>Pagination here</td>
  </tr>
</table>

I am using the keyword with XPath : .//[@id='myTable']/tr/td/@width

Because I just want to count td with a "width" attribute.

and the error: InvalidSelectorException: Message: u"invalid selector: Unable to locate an element with the XPath expression...

Any solution? thanks

like image 691
Huy Do Avatar asked Jul 16 '14 08:07

Huy Do


Video Answer


1 Answers

You can use this XPath to get <td> having style attribute value contains width :

.//table[@id='myTable']/tr/td[contains(@style, 'width')]
like image 99
har07 Avatar answered Oct 05 '22 04:10

har07