Elements in table can be accessed using xpath.
Here is the sample HTML code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<span style="font-size: 20px;"><html> <head> <tittle>Table Testing</tittle> </head> <body> <table border='1'> <tbody> <tr> <td>Pune</td> <td>Mumbai</td> </tr> <tr> <td>Hubli</td> <td>Bangalore</td> </tr> <tr> <td>Shirdi</td> <td>Nashik </td> </tr> </tbody> </table> </body> </html></span> |
To locate first “td” in first “tr” in above HTML code. Below is the xpath:
//table//tr[1]/td[1]
To locate second “td” in first “tr”. Below is the xpath.
//table//tr[1]/td[2]
To locate cells of Pune and Mumbai below is the xpath.
//table//tr[1]/td
To locate the cells of Pune, Hubli and Shirdi below is the xpath.
//table//tr/td[1]
To locate the cells of Mumbai, Bangalore and Nashik below is the xpath.
//table//tr/td[2]
To locate all 6 cells. Below is the xpath.
//table//tr/td