Handling Web Tables in Selenium [2026]
Related Product On This Page What are Web Tables?April 13, 2026 · 16 min read · Tool Comparison
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. 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: 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 Find the routine of column Read a specific cell value Search for a row by cell text Interact with elements inside a row 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. 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: 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. 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: By automating these checks, you can notice issues early, reduce manual attempt, and improve the reliability of your application ’ s data presentment. Read More: Depending on the information in the table, web table can be classified as Static web table and Dynamic 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. 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: 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 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: Read More: Here are some of the common strategies to situate table in Selenium: 1. By Tag Name 2. By ID or Class If the table has a unique identifier: java Read More: 3. By Utile for complex structures: java 4. Ideal for selecting base on category or attribute: java 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. 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: 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. Output: No of row in this table: 8 Output: No of column in this table: 9 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: Output: The Cell Value is: OLMA 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 Read More: 2. Selecting a Checkbox in a Row 3. Entering Text into an Input Field in a Table 4. Selecting an Option from a Dropdown in a Cell 5. Conditional Interaction Based on Cell Content Loop through rows to find a cell with specific textbook, then act on that row: java These interaction help simulate real user behavior and validate application logic, making your Selenium tests more comprehensive and valuable. 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 2. Links or Icons within a Cell 3. Nested Tables Sometimes a cell may contain a mini-table: java 4. Multiple Elements in One Cell (e.g., icon + text + button) 5. Handling Dynamic Nested Elements with Waits When elements laden asynchronously: java Tips: 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 2. Get All Rows Use .findElements () to find all quarrel inside the table body: java 3. Loop Through Rows and Cells Iterate through each row and extract cell (& lt; td & gt;) values: java 4. (Optional) Skip Header Row If the table has a header row (& lt; th & gt;), you can hop-skip it: java Example: Fetching Specific Cell Data java 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. 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 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 2. Scope Your Searches This reduces errors and get your code more readable: java 3. Avoid Hard-Coding Indexes 4. Use Expressed Waits 5. Handle Pagination Smartly 6. Validate Data, Not Just Presence 7. Modularize Code 8. Log and Report Clearly 9. Account for Dynamic Content 10. Test Cross-Browser 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: 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. 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. 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. On This Page # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Related Product
Handling Web Tables in Selenium [2026]
Overview
WebElement table = driver.findElement (By.id (`` table-id '')); List & lt; WebElement & gt; row = table.findElements (By.xpath (`` .//tbody/tr ''));
int columnCount = table.findElements (By.xpath (`` .//thead/th '')) .size ();
String value = rows.get (2) .findElements (By.tagName (`` td '')) .get (1) .getText ();
for (WebElement row: rows) {if (row.getText () .contains (`` John '')) {System.out.println (row.getText ()); break;}}row.findElement (By.xpath (`` .//a [text () ='Edit '] '')) .click ();
What are Web Tables?
& 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;
Trouble validating dynamic table data?
Why is Handling Web Table in Selenium important?
Types of Web Tables
1. Static Web Tables
2. Dynamic Web Tables
How to handle dynamic web tables in Selenium?
Locating Web Tables in the DOM
Common Strategies to Locate Tables in Selenium
javaWebElement table = driver.findElement (By.tagName (`` table ''));
WebElement table = driver.findElement (By.id (`` userTable '')); // or WebElement table = driver.findElement (By.className (`` data-table ''));
WebElement table = driver.findElement (By.xpath (`` //table [@ id='userTable '] ''));
WebElement table = driver.findElement (By.cssSelector (`` table.data-table ''));
Finding XPath Dynamic Web Table
Finding the turn of run-in and column of Dynamic Web Table in Selenium
//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);
//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);
Finding cell value for specific row & amp; column of Dynamic Web Table in Selenium
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);
Interacting with Table Elements
javaWebElement push = driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [2] /td [5] /button '')); button.click ();
javaWebElement checkbox = driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [3] /td [1] /input [@ type='checkbox '] '')); checkbox.click ();
javaWebElement inputField = driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [1] /td [3] /input '')); inputField.sendKeys (`` New Value '');
javaSelect dropdown = new Select (driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [4] /td [2] /select ''))); dropdown.selectByVisibleText (`` Approved '');
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;}}Handling Tables with Nested Elements
javaWebElement dropdownElement = driver.findElement (By.xpath (`` //table [@ id='orderTable '] /tbody/tr [2] /td [4] /select '')); Select dropdown = new Select (dropdownElement); dropdown.selectByVisibleText (`` Shipped '');
javaWebElement editIcon = driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [1] /td [6] /a [@ class='edit-icon '] '')); editIcon.click ();
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 ''));
javaWebElement 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
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 ();
How to get table information in Selenium Webdriver Java?
WebElement table = driver.findElement (By.id (`` exampleTable ''));
List & lt; WebElement & gt; rows = table.findElements (By.tagName (`` tr ''));
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 ();}for (int i = 1; i & lt; rows.size (); i++) {List & lt; WebElement & gt; cells = rows.get (i) .findElements (By.tagName (`` td '')); // Continue as above}String cellValue = table.findElement (By.xpath (`` //tr [2] /td [3] '')) .getText (); System.out.println (`` Cell Value: `` + cellValue);
Accomplished Code for handling Web Tables in 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
WebElement row = driver.findElement (By.xpath (`` //table [@ id='userTable '] /tbody/tr [3] '')); String name = row.findElement (By.xpath (`` td [2] '')) .getText ();
Trouble corroborate dynamic table data?
Why choose BrowserStack to run Web Table test in Selenium?
Conclusion
FAQs
Related Guides
Automate This With SUSA
Test Your App Autonomously