Reading Web Tables

The Orders Table

<table id="orders">
  <thead><tr><th>Order</th><th>Date</th><th>Amount</th><th>Status</th></tr></thead>
  <tbody>
    <tr><td>ORD-1001</td><td>02-Oct-2026</td><td>₹1,299</td><td>Delivered</td></tr>
    <tr><td>ORD-1002</td><td>09-Oct-2026</td><td>₹2,450</td><td>Shipped</td></tr>
    <tr><td>ORD-1003</td><td>15-Oct-2026</td><td>₹699</td><td>Cancelled</td></tr>
  </tbody>
</table>

Rows and Columns

List<WebElement> rows = driver.findElements(By.cssSelector("#orders tbody tr"));
System.out.println("Rows: " + rows.size());
for (WebElement row : rows) {
    List<WebElement> cells = row.findElements(By.tagName("td"));
    System.out.println(cells.get(0).getText() + " | " + cells.get(2).getText() + " | " + cells.get(3).getText());
}
// one cell directly: row 2, column 4
String status = driver.findElement(By.xpath("//table[@id='orders']/tbody/tr[2]/td[4]")).getText();

Example

Output:

Run OrdersTableTest.main()

Example output

Rows: 3
ORD-1001 | ₹1,299 | Delivered
ORD-1002 | ₹2,450 | Shipped
ORD-1003 | ₹699 | Cancelled

Table as Data

Example

Once rows are read into Java, checks are plain code. Here the cell texts (as getText() returns them) are turned into a list of maps keyed by header:

import java.util.*;

public class Main {
    public static void main(String[] args) {
        List<String> headers = List.of("Order", "Date", "Amount", "Status");
        List<List<String>> cells = List.of(
            List.of("ORD-1001", "02-Oct-2026", "₹1,299", "Delivered"),
            List.of("ORD-1002", "09-Oct-2026", "₹2,450", "Shipped"),
            List.of("ORD-1003", "15-Oct-2026", "₹699", "Cancelled"));

        List<Map<String, String>> table = new ArrayList<>();
        for (List<String> row : cells) {
            Map<String, String> m = new LinkedHashMap<>();
            for (int c = 0; c < headers.size(); c++) m.put(headers.get(c), row.get(c));
            table.add(m);
        }
        int total = 0;
        for (Map<String, String> r : table) {
            if (!r.get("Status").equals("Cancelled")) total += Integer.parseInt(r.get("Amount").replaceAll("[^0-9]", ""));
        }
        System.out.println(table.get(1));
        System.out.println("Total of non-cancelled orders: " + total);
    }
}

Output

{Order=ORD-1002, Date=09-Oct-2026, Amount=₹2,450, Status=Shipped}
Total of non-cancelled orders: 3749