automationScript

How to get data from webtable in Selenium WebDriver

WebTables are a very important part of any web based application and Often we come across a scenario where we have to validate data in a webtable. Here we have a complete example related to webtable on a webpage which will help you to get data from a Webtable in Selenium WebDriver using java. 

Webtables are created mainly in following two ways.

  1. By using the tags such as th, tr and td for header, row and cell respectively .
  2. The other way is to use mat-header, mat-row, mat-cell for header, row and cell respectively.

This method considers the table to have row tag= “tr” and cell tag to be= “td“. You can replace the tag value based on your table tag such as tr with mat-row and td with mat-cell etc. and it will work without any issue. 

Get data from WebTable in Selenium WebDriver- Example code

This method goes through each cell of the table and stores the table data in a two dimensional array and then returns the 2d array.

Checkout the code repo

Subscribe for updates