How to count td / tr count in table using Robot Framework using Selenium2Library

I use Robot Framework to automatically check the number of TD or TR in a table.

I use the Get Matching Xpath Count keyword from Selenium, however it always fails with an error.

My HTML code 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 use the keyword with Xpath: .// [@ id = 'myTable'] / tr / td / @ width

Because I just want to count td with width attribute.

and error: InvalidSelectorException: Message: u "invalid selector: Unable to find element with xpath expression ...

Any solution? thanks

+6
source share
1 answer

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

 .//table[@id='myTable']/tr/td[contains(@style, 'width')] 
+5
source

Source: https://habr.com/ru/post/972299/


All Articles