Skip to content

Locator.rows() — header-keyed table extraction as List<Map<String,String>> #53

Closed

Description

@shossain786

Problem

Locator.elements() (src/main/java/com/seleniumboot/locator/Locator.java:301-305) returns matched WebElements but nothing in Locator understands <table> structure. Extracting an HTML table today means raw nested findElements loops (thead for headers, tbody tr for rows, td per row) with manual index bookkeeping to zip each cell to its header — there's no helper anywhere in Locator or BasePage for this.

Why it matters

Every table-driven test re-implements the same header-to-cell zip logic by hand.

Proposed API

// Locator.java, terminal actions section, built on top of elements()
public List<Map<String, String>> rows() {
    // resolve this locator to a <table> (or a container of rows),
    // read header text from `th` (or first `tr`) as the map keys,
    // then for each body row zip cell text to the matching header key
}
// usage
List<Map<String, String>> data = $("table#results").rows();
assertThat(data.get(0).get("Status")).isEqualTo("Active");

Acceptance criteria

  • Locator.rows() added, built on elements()/existing resolve machinery (not a parallel implementation)
  • Header row detected via th cells (fallback: first tr if no thead/th present — decide and document the exact rule)
  • Each returned Map is ordered by header column (use LinkedHashMap) with cell text trimmed
  • Mismatched row/column counts handled without throwing an unrelated exception (define behavior: pad, truncate, or throw LocatorException with a clear message)
  • Unit tests covering: header-only, missing thead, ragged rows, empty table
  • Javadoc with a usage example matching the style of the other terminal actions in this file

Activity

  1. timothytkim commented on Sep 17, 2026

    @timothytkim
    Contributor

    Hi @shossain786 May I take this issue? Thanks

  2. shossain786 commented on Sep 17, 2026

    @shossain786
    ContributorAuthor

    Hi @timothytkim - yes, it's yours! Go ahead.

    The acceptance criteria in the issue body cover the behavior we need (header detection, LinkedHashMap ordering, ragged-row handling, tests). Feel free to ask here if anything in the spec is unclear before you start, or open a draft PR early if you want feedback on direction.

  3. timothytkim commented on Sep 17, 2026

    @timothytkim
    Contributor

    Updated on #54 @shossain786

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions