What is Table in HTML?

Tableis a kind of HTMLdata which is displayed with the help of <table> tag in conjunction with the <tr> and <td> tags. Although there are other tags for creating tables, these are the basics for creating a table in HTML. 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 in to excel we give them some heading as well. In HTML we use <th> tag for headings which defines heading of the table.

Each cell in the Excel sheet can be represented as <td> in the HTML table. The <td> elements are the data containers and these can contain all sorts of HTML elements like text, images, lists, other tables, etc.

Look at the below simple example of HTML table where first row is defined as header and later two rows are containing data.

XHTML

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

<table>

<tbody>

<tr>

<th>Automation Tool</th>

<th>Licensing</th>

<th>Market response</th>

</tr>

<tr>

<td>Selenium</td>

<td>Free</td>

<td>In</td>

</tr>

<tr>

<td>QTP</td>

<td>Paid</td>

<td>Out</td>

</tr>

</tbody>

</table>

Automation Tool

Licensing

Market response

Selenium

Free

In

QTP

Paid

Out

Handle Dynamic WebTables in Selenium Webdriver

There is no rocket science in handling of tables. All you need to is to inspect the table cell and get the HTML location of it. In most cases tables contain text data and you might simply like to extract the data given in the each row or column of the table. But sometimes tables have link or images as well, and you can easily able to perform any action on those elements if you can find the HTML location of the containing cell.

Example 1:

Let’s take an example of above table and choose Column 1 of Row 2 which is ‘Selenium’ in above case:

Example 3:

The above example is still easy as at-least you know the row number and the column number to be fetched from the table and you are able to provide it in the xpath from external excel sheet or any source of data sheet. But what would you do when the row and columns are itself dynamic and all you know is the Text value of any cell only and you like to take out the correspondence values of that particular cell.

For example all you know is the Text ‘Licensing’ in the above example and you like to record the value for that particular column only such as Free & Paid.