Types of Web Tables
- Static Web Tables: The Static web tables have fixed data that cannot be changed throughout. Due to this static nature, they are called Static tables.
- Dynamic Web Tables: The Dynamic web tables have data that can change over time, and hence the number of rows and columns can also vary depending upon the data. Due to this dynamic nature, they are called Dynamic tables.
How to handle web tables in Selenium?
Let us get started with the various operations that can be performed on a Selenium Web Table.
Finding XPath Selected Element in Dynamic Web Table
Let's start by selecting an element in the web table and finding its XPath.To locate the XPath of a UI element with the help of a browser, right-click on the desired element, and click on the "Inspect Element" to open the inspector option, which will help locate an element XPath.

Finding the number of rows and columns
//To Find the number of Rows
List<WebElement> rowsNumber = driver.findElements(By.xpath(“//*[@id="content-8b4988b9-2ec9-4e77-9b4d-9c2994bd9e8a"]/div/div/table[1]/tbody/tr[1]/td[1]”));
int row = rowsNumber.size();
System.out.println("The No. of rows in this table is : " + row);
Output: The No. of rows in this table is: 8
//To Find the number of Columns
List<WebElement> columnsNumber = driver.findElements(By.xpath("//*[@id="content-8b4988b9-2ec9-4e77-9b4d-9c2994bd9e8a"]/div/div/table[1]/thead/tr/th[1]"));
int column = columnsNumber.size();
System.out.println("The No. of columns in this table is : " + column);
Output: The No. of columns in this table is: 9
Finding cell values for specific row & column
WebElement cellAddress = Rowtable.findElement(By.xpath(“/html/body/table/tbody/tr[2]/td[2]”));
String value = cellAddress.getText();
System.out.println(“The Cell Value is : “ +value);
Output:The Cell Value is: rohan@codingninjas.com
Check this out : Xpath in Selenium
Frequently Asked Questions
-
What are Static Web Tables?
The Static web tables have fixed data that cannot be changed throughout. Due to this static nature, they are called Static tables.
-
What are Dynamic Web Tables?
The Dynamic web tables have data that can change over time, and hence the number of rows and columns can also vary depending upon the data. Due to this dynamic nature, they are called Dynamic tables.
-
How to find the X-Path of an element in a table?
To find x-path, click right and navigate over to the Inspect Element option. Then navigate the elements HTML inside the developer options and click right to copy the X-path.
-
What are Web Tables?
A web Table is similar to a standard table. Here the data is represented in a structured form using rows and columns. The critical difference between a table and a web table is that a web table is displayed on the web with the assistance of HTML code.
-
What are the various tags used in a web table?
<table> is an HTML tag that is used to define a web table. Furthermore, the <th> tag is used to define the header of a table.Similarly, <tr> and <td> tags are used to define rows and columns respectively for a web table.
Conclusion
In this article, we have extensively discussed Dynamic Web Tables in Selenium and how to handle them. If you are Preparing for interview and don't know where to start, we have got you covered, check out our expert curated courses on our website, You can also check out Coding Ninjas Studio to practice frequently asked interview problems. We hope that this blog has helped you enhance your knowledge regarding web tables and if you would like to learn more, check out our articles. Do upvote our blog to help other ninjas grow. Happy Coding!"