Handling Web Tables in Selenium [2026]

Related Product On This Page What are Web Tables?April 13, 2026 · 16 min read · Tool Comparison

Related Product

Handling Web Tables in Selenium [2026]

Ever struggled to extract data from aweb table in Seleniumwithout your tests breaking?

Many tester assume handling web tables is straightforward—just situate a cell and read its value. I opine the same until I ran into a dynamically charge table where rows refresh, columns shifted, and every locator I compose miscarry.

I spent hours tweaking XPath look and adding waits, solely to realize the issue wasn ’ t timing but the table ’ s dynamic structure. That experience showed me that web tables need a more serious-minded approach.

Overview

A web table is an HTML structure habituate to display data in rows and columns, and in Selenium, cover web tables involves locating, reading, and interacting with this tabular data during exam mechanization.

Understanding HTML Table Structure

To act with web table efficaciously in Selenium, it ’ s important to understand the core HTML tags used to build them:

  • & lt; table & gt;: Acts as the main container that holds the entire table
  • & lt; thead & gt;: Contains the header section of the table
  • & lt; tbody & gt;: Holds the main data rows of the table
  • & lt; tr & gt;: Represents a single row within the table
  • & lt; th & gt;: Defines a header cell, normally used for column titles
  • & lt; td & gt;: Defines a standard datum cell within a row

Handling Web Tables in Selenium

Handling web tables in Selenium involveslocating the table, iterating through row and columns, and extracting or interact with cell datum. The approaching varies slightly for static and active table.

Locate the table and rows

WebElement table = driver.findElement (By.id (`` table-id '')); List & lt; WebElement & gt; row = table.findElements (By.xpath (`` .//tbody/tr ''));

Find the routine of column

int columnCount = table.findElements (By.xpath (`` .//thead/th '')) .size ();

Read a specific cell value

String value = rows.get (2) .findElements (By.tagName (`` td '')) .get (1) .getText ();

Search for a row by cell text

for (WebElement row: rows) {if (row.getText () .contains (`` John '')) {System.out.println (row.getText ()); break;}}

Interact with elements inside a row

row.findElement (By.xpath (`` .//a [text () ='Edit '] '')) .click ();

This article explain how to manage web tables in Selenium, covering static and dynamic tables, effectual locater strategies, and best recitation for honest table mechanization.

What are Web Tables?

Web Tables are like normal tables where the data is exhibit in a integrated sort habituate rows and columns. The only difference is that they are displayed on the web with the help of HTML code.

& lt; table & gt;is the HTML tag that is utilize to define a web table. While& lt; th & gt;is used for delineate the coping of the table,& lt; tr & gt; and & lt; td & gt;tags are habituate for delimit row and columns severally for the web table.

Example of writing a web table use HTML:

& lt; table & gt; & lt; tr & gt; & lt; th & gt; First Name & lt; /th & gt; & lt; th & gt; Last Name & lt; /th & gt; & lt; th & gt; Age & lt; /th & gt; & lt; /tr & gt; & lt; tr & gt; & lt; td & gt; Jill & lt; /td & gt; & lt; td & gt; Ann & lt; /td & gt; & lt; td & gt; 24 & lt; /td & gt; & lt; /tr & gt; & lt; tr & gt; & lt; td & gt; Eve & lt; /td & gt; & lt; td & gt; Anderson & lt; /td & gt; & lt; td & gt; 34 & lt; /td & gt; & lt; /tr & gt; & lt; /table & gt;

Web Table Example

According toCrissy Joshua, an expert software tester,working with web tablesbecomes far more reliable whentests concentrate on row-based data validationinstead of hardcoded cell positions, as this approachadapts better to dynamic content changesand reduces test maintenance.

As web table become more dynamic and interactive, validating their behavior across different browsers and environment becomes critical.

Platforms like helps teams run on real browser and devices, ensuring web tables render correctly and table interaction work reliably without keep complex local frame-up.

Trouble validating dynamic table data?

Changing run-in and columns separate local tests. Run Selenium web table exam on real browser environments.

Why is Handling Web Table in Selenium important?

Web tables often check critical datum that drives user decisions, such as pricing, inventory, user info, or transaction chronicle. Ensuring this data is displayed correctly and functions as look is vital for application quality.

Handling web tables in Selenium is significant because it allows testers to:

  • Verify dynamic datumrender from APIs or databases.
  • Validate sorting, filtering, and paginationfunctionality.
  • Perform actionswithin table cells like tick buttons, checking boxes, or editing stimulant.
  • Ensure consistencyacross different browser and devices.

By automating these checks, you can notice issues early, reduce manual attempt, and improve the reliability of your application ’ s data presentment.

Read More:

Types of Web Tables

Depending on the information in the table, web table can be classified as Static web table and Dynamic web tables.

1. Static Web Tables

These tables have repair data that remains unaltered throughout. Due to the static nature of their content, they are call Static web tables.

2. Dynamic Web Tables

These tables have data that changes over time, and hence the number of rows and columns might also vary depending upon the data shifts. Due to the active nature of their content, they are called Dynamic web table.

Often, the functionalities of web coating depend on the data pack by Dynamic web tables, as they act as the information source for the functional faculty in many cases. Thus, handling dynamic web tables using Selenium WebDriver is essential for QAs to run test instance that shape website performance.

Read More:

How to handle dynamic web tables in Selenium?

Understand handling web tables in Selenium with the assist of an instance. The example uses the data presented using web table on the IPO Filings Data section of the NYSE (New York Stock Exchange) website to demonstrate the procedure.

Dynamic Web Table on the IPO Filings Data page of NYSE

Locating Web Tables in the DOM

Before interact with a web table using Selenium, it & # 8217; s crucial to understand how tables are structured in the HTML DOM. Most web tables use a combination of the following tatter:

  • & lt; table & gt;– defines the table itself
  • & lt; thead & gt;– contains header wrangle
  • & lt; tbody & gt;– contains the main information rows
  • & lt; tr & gt;– defines each row
  • & lt; th & gt;– defines a header cell
  • & lt; td & gt;– defines a measure cell

Read More:

Common Strategies to Locate Tables in Selenium

Here are some of the common strategies to situate table in Selenium:

1. By Tag Name

java

WebElement table = driver.findElement (By.tagName (`` table ''));

2. By ID or Class

If the table has a unique identifier:

java

WebElement table = driver.findElement (By.id (`` userTable '')); // or WebElement table = driver.findElement (By.className (`` data-table ''));

Read More:

3. By

Utile for complex structures:

java

WebElement table = driver.findElement (By.xpath (`` //table [@ id='userTable '] ''));

4.

Ideal for selecting base on category or attribute:

java

WebElement table = driver.findElement (By.cssSelector (`` table.data-table ''));

Once the table element is located, you can use nested calls to cross rows and columns, making it possible to pull or validate data efficiently.

Finding XPath Dynamic Web Table

Select an element in the web table and find its XPath. For Chrome, right-click and inspect the give element to find its XPath.

To find the XPath of a UI factor in Firefox, right-click on the craved element, go to “Inspect Element” to open the inspector which will help identify its.

Finding XPath of selected element using Inspect Element for Google Chrome

Read More:

Finding the turn of run-in and column of Dynamic Web Table in Selenium

Here ’ s the codification snippet to find the total number of wrangle and column for the above Dynamic Web Table

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

//Finding number of Rows List & lt; WebElement & gt; rowsNumber = driver.findElements (By.xpath (“ // * [@ id= '' content-8b4988b9-2ec9-4e77-9b4d-9c2994bd9e8a ''] /div/div/table [1] /tbody/tr [1] /td [1] ”)); int rowCount = rowsNumber.size (); System.out.println (`` No of quarrel in this table: `` + rowCount);

Output: No of row in this table: 8

//Finding turn of Columns List & lt; WebElement & gt; columnsNumber = driver.findElements (By.xpath (`` // * [@ id= '' content-8b4988b9-2ec9-4e77-9b4d-9c2994bd9e8a ''] /div/div/table [1] /thead/tr/th [1] '')); int columnCount = columnsNumber.size (); System.out.println (`` No of columns in this table: `` + columnCount);

Output: No of column in this table: 9

Finding cell value for specific row & amp; column of Dynamic Web Table in Selenium

Identify the data present in the 6th Row and 6th Column of the afford dynamic web table on the IPO Filings Data page of the NYSE website:

WebElement cellAddress = Rowtable.findElement (By.xpath (“ // * [@ id= '' content-8b4988b9-2ec9-4e77-9b4d-9c2994bd9e8a ''] /div/div/table [1] /tbody/tr [4] /td [3] ”)); String value = cellAddress.getText (); System.out.println (“ The Cell Value is: “ +value);

Output: The Cell Value is: OLMA

Interacting with Table Elements

Beyond say data, many web table include synergistic elements like buttons, checkboxes, dropdowns, or comment fields within their cells.

Automating these interactions with Selenium is essential for corroborate real-world workflow such as redaction records, selecting rows, or triggering action from a table.

Common Interactions in Web Tables

1. Clicking a Button in a Table Cell

java

WebElement push = driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [2] /td [5] /button '')); button.click ();

Read More:

2. Selecting a Checkbox in a Row

java

WebElement checkbox = driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [3] /td [1] /input [@ type='checkbox '] '')); checkbox.click ();

3. Entering Text into an Input Field in a Table

java

WebElement inputField = driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [1] /td [3] /input '')); inputField.sendKeys (`` New Value '');

4. Selecting an Option from a Dropdown in a Cell

java

Select dropdown = new Select (driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [4] /td [2] /select ''))); dropdown.selectByVisibleText (`` Approved '');

5. Conditional Interaction Based on Cell Content

Loop through rows to find a cell with specific textbook, then act on that row:

java

List & lt; WebElement & gt; rows = driver.findElements (By.xpath (`` //table [@ id='userTable '] /tbody/tr '')); for (WebElement row: rows) {String position = row.findElement (By.xpath (`` td [3] '')) .getText (); if (status.equals (`` Pending '')) {row.findElement (By.xpath (`` td [5] /button '')) .click (); break;}}

These interaction help simulate real user behavior and validate application logic, making your Selenium tests more comprehensive and valuable.

Talk to an Expert

Handling Tables with Nested Elements

Table cells often contain nested constituent like dropdowns, buttons, links, image, or even other tables. These complex structures require precise navigation and dynamic locators when with Selenium.

Read More:

Mutual Scenarios and How to Handle Them

1. Dropdowns inside Table Cells

java

WebElement dropdownElement = driver.findElement (By.xpath (`` //table [@ id='orderTable '] /tbody/tr [2] /td [4] /select '')); Select dropdown = new Select (dropdownElement); dropdown.selectByVisibleText (`` Shipped '');

2. Links or Icons within a Cell

java

WebElement editIcon = driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [1] /td [6] /a [@ class='edit-icon '] '')); editIcon.click ();

3. Nested Tables

Sometimes a cell may contain a mini-table:

java

WebElement nestedTable = driver.findElement (By.xpath (`` //table [@ id='mainTable '] /tbody/tr [3] /td [2] //table '')); List & lt; WebElement & gt; nestedRows = nestedTable.findElements (By.tagName (`` tr ''));

4. Multiple Elements in One Cell (e.g., icon + text + button)

java

WebElement cell = driver.findElement (By.xpath (`` //table [@ id='productTable '] /tbody/tr [5] /td [3] '')); String price = cell.findElement (By.className (`` price-text '')) .getText (); cell.findElement (By.tagName (`` button '')) .click (); // Click 'Add to Cart ' button

5. Handling Dynamic Nested Elements with Waits

When elements laden asynchronously:

java

WebDriverWait expect = new WebDriverWait (driver, Duration.ofSeconds (10)); WebElement dynamicIcon = wait.until (ExpectedConditions.visibilityOfElementLocated (By.xpath (`` //table [@ id='dataTable '] /tbody/tr [2] /td [4] //span [@ class='status-icon '] ''))); dynamicIcon.click ();

Tips:

  • Use comparative XPath to scope searches within a row or cell.
  • Always use explicit waits for dynamic/nested elements to avoid.
  • For better legibility, stock parent row or cell as WebElement and navigate from there.

How to get table information in Selenium Webdriver Java?

To extract datum from a web table using Selenium WebDriver in Java, postdate these canonical steps:

1. Locate the Table

Identify the table element using By.id, By.xpath, or other locators.

java

WebElement table = driver.findElement (By.id (`` exampleTable ''));

2. Get All Rows

Use .findElements () to find all quarrel inside the table body:

java

List & lt; WebElement & gt; rows = table.findElements (By.tagName (`` tr ''));

3. Loop Through Rows and Cells

Iterate through each row and extract cell (& lt; td & gt;) values:

java

for (WebElement row: rows) {List & lt; WebElement & gt; cells = row.findElements (By.tagName (`` td '')); for (WebElement cell: cells) {System.out.print (cell.getText () + `` ``);} System.out.println ();}

4. (Optional) Skip Header Row

If the table has a header row (& lt; th & gt;), you can hop-skip it:

java

for (int i = 1; i & lt; rows.size (); i++) {List & lt; WebElement & gt; cells = rows.get (i) .findElements (By.tagName (`` td '')); // Continue as above}

Example: Fetching Specific Cell Data

java

String cellValue = table.findElement (By.xpath (`` //tr [2] /td [3] '')) .getText (); System.out.println (`` Cell Value: `` + cellValue);

This method works good forstaticand moderatelydynamictables. For more complex tables (e.g., with folio or dynamic loading), additional handling may be ask using waits or scrolling.

Accomplished Code for handling Web Tables in Selenium

Purpose: Identify the figure of run-in & amp; columns and bring the cell value for a given row and column from the IPO Filing Data web table on the NYSE website using Selenium

//Opening Chrome Browser package browser; significance org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class BrowserSelection {static WebDriver driver; public still WebDriver usingChrome () {System.setProperty (`` webdriver.chrome.driver '', `` E: \SeleniumLibs\\chromedriver_win32\chromedriver.exe ''); driver = new ChromeDriver (); driver.manage () .window () .maximize (); return driver;}} //Test to handle dynamic web table using Selenium WebDriver packet dynamicwebtable; import java.awt.AWTException; import java.awt.Robot; import java.awt.event.KeyEvent; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import org.testng.annotations.AfterMethod; signification org.testng.annotations.BeforeMethod; importation org.testng.annotations.Test; importation browser.BrowserSelection; public class DynamicWebTableTest {WebDriver driver; @ BeforeMethod public nothingness openBrowser () {driver = BrowserSelection.usingChrome ();} @ Test public void tripDetails () throws InterruptedException, AWTException {//Modify Wait time as per the Network Ability in the Thread Sleep method driver.get (`` https: //www.nyse.com/ipo-center/filings ''); driver.manage () .timeouts () .implicitlyWait (10, TimeUnit.SECONDS); Thread.sleep (5000); //Finding routine of Rows List & lt; WebElement & gt; rowsNumber = driver.findElements (By.xpath (`` // * [@ id= '' content-8b4988b9-2ec9-4e77-9b4d-9c2994bd9e8a ''] /div/div/table [1] /tbody/tr [1] /td [1] '')); int rowCount = rowsNumber.size (); System.out.println (`` No of rows in this table: `` + rowCount); //Finding act of Columns List & lt; WebElement & gt; columnsNumber = driver.findElements (By.xpath (`` // * [@ id= '' content-8b4988b9-2ec9-4e77-9b4d-9c2994bd9e8a ''] /div/div/table [1] /thead/tr/th [1] '')); int columnCount = columnsNumber.size (); System.out.println (`` No of column in this table: `` + columnCount); //Finding cell value at 4th row and 3rd column WebElement cellAddress = Rowtable.findElement (By.xpath (“ // * [@ id= '' content-8b4988b9-2ec9-4e77-9b4d-9c2994bd9e8a ''] /div/div/table [1] /tbody/tr [4] /td [3] ”)); String value = cellAddress.getText (); System.out.println (“ The Cell Value is: “ +value); driver.quit ();}}

Best Practices for Web Table Automation

Automating web table in Selenium can get complex, particularly with dynamical content, pagination, and nested elements. Following best pattern ascertain your test scripts are reliable, maintainable, and scalable.

1. Use Stable and Unique Locators

  • Prefer id, data-*attributes, or stable class names over sheer XPath.
  • Keep your picker resilient to layout or content changes.

2. Scope Your Searches

  • Locate the row first, then find specific cells or constituent within it.

This reduces errors and get your code more readable:

java

WebElement row = driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [3] '')); String name = row.findElement (By.xpath (`` td [2] '')) .getText ();

3. Avoid Hard-Coding Indexes

  • Use header label or dynamic logic rather of fixed row/column indices where possible.
  • This improves adaptability to tabularise structure changes

4. Use Expressed Waits

  • Always wait for the table and its message to load before interacting.
  • Prevent flaky tests by usingWebDriverWait and ExpectedConditions.

5. Handle Pagination Smartly

  • Create reusable logic to loop through all pages when needed.
  • Ensure you don & # 8217; t miss quarrel split across page.

6. Validate Data, Not Just Presence

  • Go beyond control if elements exist—verify actual data values for accuracy.
  • Use assertions to compare expected and actual value.

7. Modularize Code

  • Create recyclable methods for activeness like fetching row count, extracting cell values, or interact with dropdowns.
  • Keeps test cases light and maintainable.

8. Log and Report Clearly

  • When validating large datasets, include helpful logs for mismatch.
  • Useful for debugging and review.

9. Account for Dynamic Content

  • If data update frequently (like splashboard), check your tests adapt to changes in content or row order.

10. Test Cross-Browser

  • Web table may render differently in some browsers. Use tools like BrowserStack to prove across environment.

Trouble corroborate dynamic table data?

Changing wrangle and column break local tests. Run Selenium web table tryout on real browser environments.

Why choose BrowserStack to run Web Table test in Selenium?

Validating web tables topically can miss issues that surface only on specific browser, devices, or environments. BrowserStack Automate helps see that your Selenium-based web table tests remain accurate, reliable, and reflective of.

Key benefits of using BrowserStack Automate for web table testing include:

  • Real device and browser reporting:Test web table rendering and interactions on 3,500+ real devices and browser, assure ordered behavior across different screen resolutions, operating scheme, and browser engines.
  • executing:Run multiple Selenium script simultaneously to reduce overall execution clip, especially useful when validating table across multiple pages, datasets, or user workflow.
  • Zero setup and instant entree:Eliminate the need for maintaining local infrastructure or practical machine. Start testing immediately using pre-configured browser–device combinations.
  • Support for dynamic content:Web tables often load or update datum dynamically. BrowserStack ’ s real-browser examination ensures accurate interaction and validation even for -heavy or ofttimes refreshed tables.
  • integration:Easily integrate with CI instrument like or GitHub Actions to run web table validations mechanically on every form or deployment.
  • Rich debugging capabilities:Access screenshots, picture recordings, and detailed logs for every test session to quickly identify issues related to table loading, alignment, or user interaction.
  • Geolocation and net model:Validate how web tables perform under different network conditions and regions to ensure a smooth experience for users worldwide.

By scat Selenium web table tests on BrowserStack Automate, teams can get layout, data, and interaction issues early, delivering consistent and authentic table-driven experiences across all devices and platforms.

Conclusion

As demonstrated, handling the dynamic web table on a website is easy enough habituate Selenium. Run the code, evaluate the results, and start applying the like process to website with this particular functionality.

It is crucial to run Selenium trial on real browser and device to ensure testing in. BrowserStack offer a of 3500+ real browser and device for test purposes. Simply sign up, choose the required device-browser-OS combination from the, andstart prove website for free.

Tags

FAQs

Web tables can be active, with run-in and column change due to sorting, paging, filters, or unrecorded data updates, do element locators treacherous if not cover aright.

Dynamic tables can be handled by using stable XPath or CSS selectors, iterating through rows and columns, locating cells establish on text rather than index, and avoiding hardcoded positions.

BrowserStack Automate runs Selenium web table tests on real browser and devices while providing screenshots, video, and logs, making it easier to debug table-related issues across environment.

20,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free