Handling web tables in selenium

A basic web table will have these below components:
header, body and footer
Header cells- th
Body cells – td
Rows – tr
Header and footer are optional for a webtable.
Some of the webpages may or may not have header and footer,

if there is no thead, then header is absent and we can deal the table with the tbody only.
A basic webtable HTML looks like below:


Let’s see the implementation:

Another way of working tables:
use of xpath: if we inspect webtable cells with the firebug on webpage, the xpath mostly remains same except the index of tr and td tag…

As you can see in above screenshot, item TFS is on 2nd row and 4th column…
so we can use 2 for loops to iterate the tr and td tags to get the cell values,
let’s see

Content posted is based on learning or working experience, please leave comments if anything needs to be added or updated, discuss your queries on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: