Class TableElement

java.lang.Object
com.vaadin.testbench.TestBenchElement
com.vaadin.flow.component.html.testbench.TableElement
All Implemented Interfaces:
CanCompareScreenshots, HasCallFunction, HasDriver, HasElementQuery, HasPropertySettersGetters, HasSearchContext, HasTestBenchCommandExecutor, org.openqa.selenium.SearchContext, org.openqa.selenium.TakesScreenshot, org.openqa.selenium.WebElement, org.openqa.selenium.WrapsElement

public class TableElement extends TestBenchElement
A TestBench element representing a <table> element.
Since:
25.3
  • Constructor Details

    • TableElement

      public TableElement()
  • Method Details

    • getAllRows

      public List<TableRowElement> getAllRows()
      Returns every row of this table, walking its sections in document order. For a table rendered by Table that is the <thead> rows, then the rows of each <tbody>, then the <tfoot> rows; on a page that writes the sections in some other order, the result follows the markup rather than that order.

      The name matches Table.getAllRows(): this is the only row accessor here that spans every kind of section. getHeaderRows(), getBodyRows() and getFooterRows() each stay within one kind ? though a table may have several <tbody> elements, so getBodyRows flattens those ? and TableSectionElement.getRows() returns the rows of a single element.

      Returns:
      all the rows of this table.
    • getRow

      public TableRowElement getRow(int index)
      Returns the row at the given zero-based position in getAllRows(), so the index runs across the sections rather than within one.
      Parameters:
      index - the zero-based position of the row.
      Returns:
      the row at that position.
    • getCell

      public TableCellElement getCell(int row, int column)
      Returns the cell at the given zero-based row and column of this table. Both indices are zero-based, as in GridElement.getCell. The row index runs across the sections, as in getAllRows(); equivalent to getRow(row).getCells().get(column).

      The resemblance to GridElement.getCell stops at the numbering, though. A grid is a strict rectangle whose column index picks a column rather than a position, so there every row has one cell per column and the two always agree. A table does not have to be rectangular.

      Both indices count elements as they are written, not grid positions. A cell carrying a colspan or rowspan occupies one position in the row it is written in and none at all in the rows or columns it reaches into, so on a table with spans these indices drift away from what is on screen. Given:

      
       <tr><th rowspan="2">Helsinki</th><td>Travel</td></tr>
       <tr><td>Design</td></tr>
       
      getCell(0, 0) is the <th> and getCell(0, 1) is "Travel", while getCell(1, 0) is "Design" ? not the <th> that visually covers that position, and there is no index at which the second row yields it. To assert on a spanned cell, reach it through the row that writes it and check its rowspan or colspan attribute.
      Parameters:
      row - the zero-based position of the row in getAllRows().
      column - the zero-based position of the cell within that row, counting only the cells that row writes.
      Returns:
      the cell at that position.
    • getHeaderRows

      public List<TableRowElement> getHeaderRows()
      Returns the rows of this table's <thead>.
      Returns:
      the header rows, or an empty list if the table has no <thead>.
    • getBodyRows

      public List<TableRowElement> getBodyRows()
      Returns the rows of this table's <tbody> elements, in document order. Use getBodies() to keep them grouped by body.
      Returns:
      the body rows, or an empty list if the table has no <tbody>.
    • getFooterRows

      public List<TableRowElement> getFooterRows()
      Returns the rows of this table's <tfoot>.
      Returns:
      the footer rows, or an empty list if the table has no <tfoot>.
    • getBodies

      public List<TableBodyElement> getBodies()
      Returns the <tbody> elements of this table, in document order. A table may have several, each holding its own rows.
      Returns:
      the table bodies.
    • getHead

      public TableHeadElement getHead()
      Returns this table's <thead>.
      Returns:
      the header section.
      Throws:
      org.openqa.selenium.NoSuchElementException - if the table has none. Ask hasHead() first to check without failing; getHeaderRows() is not the same question, since an empty <thead> has no rows.
    • hasHead

      public boolean hasHead()
      Reports whether this table has a <thead>, without failing if it does not.
      Returns:
      true if the section is present.
    • getFoot

      public TableFootElement getFoot()
      Returns this table's <tfoot>.
      Returns:
      the footer section.
      Throws:
      org.openqa.selenium.NoSuchElementException - if the table has none. Ask hasFoot() first to check without failing; getFooterRows() is not the same question, since an empty <tfoot> has no rows.
    • hasFoot

      public boolean hasFoot()
      Reports whether this table has a <tfoot>, without failing if it does not.
      Returns:
      true if the section is present.
    • getCaption

      public TableCaptionElement getCaption()
      Returns this table's caption.
      Returns:
      the <caption>.
      Throws:
      org.openqa.selenium.NoSuchElementException - if the table has none. Ask hasCaption() first to check without failing.
    • hasCaption

      public boolean hasCaption()
      Reports whether this table has a <caption>, without failing if it does not.
      Returns:
      true if the caption is present.
    • getColumnGroups

      public List<TableColumnGroupElement> getColumnGroups()
      Returns the column groups of this table, in document order.
      Returns:
      the table's <colgroup> elements.
    • getColumnCount

      public int getColumnCount()
      Returns how many columns wide this table is once colspan and rowspan are resolved, which is what the widest row occupies on screen rather than the largest number of cells any row writes.

      The layout is computed in the browser, and only the count comes back, so this is one round trip whatever the size of the table.

      Returns:
      the number of columns, or 0 for a table with no cells.
    • getCellCovering

      public TableCellElement getCellCovering(int row, int column)
      Returns the cell covering the given zero-based slot of this table as it appears on screen, resolving colspan and rowspan. Where getCell(int, int) counts the cells a row writes, this counts the positions a reader sees, so a cell spanning two rows is returned for both of them.

      The layout is computed in the browser, so this is a single round trip rather than one per cell; the whole grid comes back with it, though, and nothing is cached, since the page is free to change between calls. Reach for the slots an assertion is about rather than walking every slot of a large table.

      Parameters:
      row - the zero-based row of the slot.
      column - the zero-based column of the slot.
      Returns:
      the cell covering that slot.
      Throws:
      org.openqa.selenium.NoSuchElementException - if the table has no such slot, or no cell reaches it.
      See Also: