Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath to get rows inside a table

Tags:

java

xpath

I have a html table like:

<table ..... class="cars">

<tr class="item-odd">
...
</tr>
<tr class="item-even">
</tr>

</table>

How could I get the table rows using xpath?

//tr[contains(@class, ???)

can I use OR in there somehow to say item-odd|item-even

like image 639
mrblah Avatar asked Jan 06 '10 23:01

mrblah


People also ask

How do I find the XPath of a column in a table?

Number of columns of the web table in Selenium are calculated using XPath (//*[@id='customers']/tbody/tr[2]/td). XPath of the rows and columns are obtained using the inspect tool in the browser to handle tables in Selenium for automated browser testing.


1 Answers

You can get the rows like this:

//table[@class='cars']/tr

To get the item-odd rows, you would do this:

//table[@class='cars']/tr[@class='item-odd']

Yes, you can use or, e.g.:

//table[@class='cars']/tr[@class='item-odd' or @class='item-even']

See http://www.w3.org/TR/xpath for more details.

like image 124
Malcolm Sparks Avatar answered Sep 28 '22 02:09

Malcolm Sparks