Web Table in Selenium

Let’s see, How can you handle the Web Table in Selenium. First, let’s understand What is Web Table?

Basically web table is an HTML Table. In this data display in the form of table with the help of <table> tag in conjunction with the <tr>and <td> tags. Here tag <tr> defines the row and tag <td> defines the column of the table.

 

Excel sheet is a simple example of table structures. Whenever we put some data into excel we give them some heading as well. In HTML, we use <th> tag for headings which defines heading of the table.

Let’s see an example of Web Table.

WebTable in Selenium

The above-shown table is a Web table.

 

So we have seen the web table. We have understood the structure of Web table.

Let’s discuss some customized XPath, To understand how we can locate the elements in Web table. Suppose we have the table with id ‘table’.

 

Sample xpaths —

1. //table[@id=’table’]/tbody/tr[2] – It is representing the comple 2nd row of web table.

2. //table[@id=’table’]/tbody/tr[2]/tr[3]  – It is representing the 2nd row  and third column of web table.

3. //table[@id= ‘table’]/tbody/tr/tr[3]  – It is representing the complethird column of web table.

4. //table[@id= ‘table’]/tbody/tr/tr  – It is representing the all cells of web table.

 

Mow Let’s see some practical examples. We are using Rediff.com to perform our Testing.

 

Extract all Present Rows from the WebTable

In this example, We will see how can we extract the complete web Table.

 

How to get Total Number of Columns in Webtable

In the below example we will see, How we can get the count of all columns present in the table.

This Test will get the count of columns present in the table on rediff.com page.

 

 

How to get values of complete Columns in Webtable

In the below example we will see, How we can get all values in specific column present in the table.

 

How to get values of complete Row in Webtable

In the below example we will see, How we can get all values in specific column present in the table.

 

So we have seen how can we deal with the web Tables in the selenium. It’s very easy to manage the web tables in the selenium. You just need to concentrate on your locator.

 

To Play around the web table. All you need to do, Create correct and logical locators and prepare selenium script will become very easy.

0 Comment

Leave a Reply