How to Handle Web Table In Selenium? – Devstringx

Back to Blog

How to Handle Web Table In Selenium? – Devstringx

Website tables are an important way to provide information to users.  Automation of the table extraction process has applications in web mining, information retrieval, knowledge acquisition, and summarization. The article discusses information extraction from HTML tables embedded in web pages.

Nowadays, All enterprise applications like Customer Relationship Management (CRM) Software, Project Management Tools, Marketing Automation, Enterprise Resource Planning (ERP) Software, and Treasury Management systems (TMS).

The Data are displayed in the form of rows and columns. These data displayed can either be static or dynamic in nature. So, this arrangement of data we called Web Table. Web tables are mainly used in scenarios where you need to display the data or information in tabular format.

Web Table As Given Below As:

This table shows the information on the different monuments of different countries and where these are located and their rank, size, height, built.

Web Table

Appropriate Use of Tables

Tables can be useful to present tabular data in an organized way when dealing with the following types of data:

  1. Quantitative Information – Tables show a certain quantity, range, or amount of information retrieval, knowledge acquisition, and summarization.
  2. Data Comparison – Tables show different amounts of data. It shows a comparison of different data like in the above table shows different monument information.
  3. If you have more than one set of values that are directly related.

HTML Tables

In HTML the table contents are confined to the body of text within <table> and </table> html tags.Web Table is a web element like textbox, checkbox, radio button. <table>is the HTML tag which represent the table. While <th> represent heading of table, <tr> represent row of the table and <td> represent column of the table.

Example of Writing a Web Table Using HTML:






<td>Saudi Arabia</td>





Selenium is a widely used automation suite. But there is no method to handle the web table. If you want to get the values of the table. Then you have to use XPath.

There are Two Types of Web Tables
  1. Static Web Tables= the data remain fixed not changed. Its row and column are not updated
  2. Dynamic Web Tables= the data changes according to the requirement. Its row and column change depending upon the data shifts

Read Also – Get The Execution Time of Multiple Methods In Selenium Java

How to handle and get different values in the table?
  1. Launch new Browser
  2. Open URL “
  1. Suppose you want to get the values of ‘country’ column

//table[@summary=’Sample Table’]//tbody//tr[‘row_number’]//td[(text())][‘column_number’]

For example country column number is 1

//table [@summary=’SampleTable’]//tbody//tr[‘row_number’]//td[(text())][1]

  1. First you get the values of all rows web element




List<Web Element>country_list = driver.findElements(By.xpath(“//table[@summary=’Sample Table’]//tbody//tr//td[(text())][1]”));

2. Using for loop to read all the values of the table

for(int i=1;i<=country_list.size();i++) {String country_text=driver.findElement(By.xpath(“//table[@summary=’Sample Table’]//tbody//tr[“+i+”]//td[(text())][1]”));


3. Using the get text method to get the values

String Country_Name=country_text.getText();System.out.println(“Country Name =”+country_text);

Share this post

Back to Blog