Class TreeGridElement

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 TreeGridElement extends GridElement
TestBench Element API for TreeGrid.
  • Constructor Details

    • TreeGridElement

      public TreeGridElement()
  • Method Details

    • scrollToRow

      @Deprecated(since="25.0") public void scrollToRow(int row)
      Deprecated.
      since 25.0. Please update your code to use scrollToRowByPath(int...) with a single index where you want to scroll to a root-level row. In Vaadin 26, this deprecated method will be changed to accept a flat index and behave as scrollToRowByFlatIndex(int), which may break tests if not updated.
      Scrolls to the row with the given index in the root level.
      Overrides:
      scrollToRow in class GridElement
      Parameters:
      row - the row to scroll to
    • scrollToRowAndWait

      @Deprecated(since="25.0", forRemoval=true) public void scrollToRowAndWait(int row)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 25.0 and will be removed in Vaadin 26. Use scrollToRowByPath(int...) with a single index instead.
      Scrolls to the row with the given index in the root level.
      Parameters:
      row - the row to scroll to
    • scrollToRowAndWait

      @Deprecated(since="25.0", forRemoval=true) public void scrollToRowAndWait(int... indexes)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 25.0 and will be removed in Vaadin 26. Use scrollToRowByPath(int...) instead.
      Scrolls to the row with the given indexes. The indexes are hierarchical, starting with the root index.
      Parameters:
      indexes - the indexes of the row to scroll to
    • scrollToFlatRowAndWait

      @Deprecated(since="25.0", forRemoval=true) public void scrollToFlatRowAndWait(int row)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 25.0, and will be removed in Vaadin 26. Use scrollToRowByFlatIndex(int) instead.
      Scrolls to the row with the given flat index.
      Parameters:
      row - the row to scroll to
    • scrollToRowByFlatIndex

      public void scrollToRowByFlatIndex(int rowFlatIndex)
      Scrolls to a row at the given flat index, an index that represents the position across all rows, including children of expanded rows.

      This method works best with HierarchyFormat#FLATTENED data providers, where the full hierarchy is known upfront and flat indexes remain stable during scrolling.

      When using HierarchyFormat#NESTED data providers, the hierarchy is resolved lazily while scrolling, so flat indexes may shift as more levels are discovered. With these data providers, consider using scrollToRowByPath(int...), which targets rows by their hierarchical path.

      Parameters:
      rowFlatIndex - the flat index of the row to scroll to
    • scrollToRowByPath

      public int scrollToRowByPath(int... path)
      Scrolls to a row specified by the given hierarchical path and returns its flat index. The returned index can then be used with other methods, for example GridElement.getRow(int):
       int rowFlatIndex = treeGrid.scrollToRowByPath(2, 1);
       assertEquals("Row 2-1", treeGrid.getRow(rowFlatIndex).getText());
       

      The hierarchical path is an array of 0-based indexes, where each index refers to a child of the row at the previous index. Scrolling continues until it reaches the last index in the array or encounters a collapsed row.

      For example, given { 2, 1, ... } as the path, this method will first try to scroll to the row at index 2 in the root level. If that row is expanded, it will then try to scroll to the row at index 1 among its children, and so forth.

      NOTE: This method works only with tree grids using data providers that return data in HierarchyFormat#NESTED. For HierarchyFormat#FLATTENED data providers, use scrollToRowByFlatIndex(int) with a flat index instead.

      Parameters:
      path - an array of indexes representing the path to the target row
      Returns:
      the flat index of the row that was scrolled to
    • getCellWaitForRow

      public GridTHTDElement getCellWaitForRow(int rowFlatIndex, int colIndex)
      Gets the grid cell for the given row and column index.

      For the column index, only visible columns are taken into account.

      Automatically scrolls the given row into view and waits for the row to load.

      Parameters:
      rowFlatIndex - the flat index of the row
      colIndex - the column index
      Returns:
      the grid cell for the given coordinates
    • getCellWaitForRow

      public GridTHTDElement getCellWaitForRow(int rowFlatIndex, GridColumnElement column)
      Gets the grid cell for the given row and column.

      Automatically scrolls the given row into view and waits for the row to load.

      Parameters:
      rowFlatIndex - the flat index of the row
      column - the column element for the column
      Returns:
      the grid cell for the given coordinates
    • expandWithClick

      public void expandWithClick(int rowFlatIndex)
      Expands the row at the given index in the grid. This expects the first column to have the hierarchy data.
      Parameters:
      rowFlatIndex - the flat index of the row to expand
      See Also:
    • expandWithClick

      public void expandWithClick(int rowFlatIndex, int hierarchyColumnIndex)
      Expands the row at the given index in the grid with the given hierarchical column index.
      Parameters:
      rowFlatIndex - the flat index of the row to expand
      hierarchyColumnIndex - the index of the hierarchy column
    • collapseWithClick

      public void collapseWithClick(int rowFlatIndex)
      Collapses the row at the given index in the grid. This expects the first column to have the hierarchy data.
      Parameters:
      rowFlatIndex - the flat index of the row to collapse
      See Also:
    • collapseWithClick

      public void collapseWithClick(int rowFlatIndex, int hierarchyColumnIndex)
      Collapses the row at the given index in the grid with the given hierarchical column index.
      Parameters:
      rowFlatIndex - the flat index of the row to collapse
      hierarchyColumnIndex - the index of the hierarchy column
    • isRowExpanded

      public boolean isRowExpanded(int rowFlatIndex, int hierarchyColumnIndex)
      Returns whether the row at the given index is expanded or not.
      Parameters:
      rowFlatIndex - the flat index of the row
      hierarchyColumnIndex - the index of the hierarchy column
      Returns:
      true if expanded, false if collapsed
    • isRowCollapsed

      public boolean isRowCollapsed(int rowFlatIndex, int hierarchyColumnIndex)
      Returns whether the row at the given index is collapsed or not.
      Parameters:
      rowFlatIndex - the flat index of the row
      hierarchyColumnIndex - the index of the hierarchy column
      Returns:
      true if collapsed, false if expanded
    • hasExpandToggle

      public boolean hasExpandToggle(int rowFlatIndex, int hierarchyColumnIndex)
      Check whether the given indices correspond to a cell that contains a visible hierarchy toggle element.
      Parameters:
      rowFlatIndex - the flat index of the row
      hierarchyColumnIndex - the index of the hierarchy column
      Returns:
      true if this cell has the expand toggle visible
    • getExpandToggleElement

      public org.openqa.selenium.WebElement getExpandToggleElement(int rowFlatIndex, int hierarchyColumnIndex)
      Gets the 'vaadin-grid-tree-toggle' element for the given row.
      Parameters:
      rowFlatIndex - the flat index of the row
      hierarchyColumnIndex - the index of the hierarchy column
      Returns:
      the span element that is clicked for expanding/collapsing a rows
      Throws:
      org.openqa.selenium.NoSuchElementException - if there is no expand element for this row
    • isDetailsOpen

      public boolean isDetailsOpen(int rowFlatIndex)
      Returns true if details are open or the given row index.
      Parameters:
      rowFlatIndex - the flat index of the row
      Returns:
      true if details are shown in the target row
    • hasRow

      public boolean hasRow(int rowFlatIndex)
      Returns true if given index has tr element for the row
      Parameters:
      rowFlatIndex - the flat index of the row
      Returns:
      true if there is tr element for the row, false otherwise
    • getRowCount

      public int getRowCount()
      Gets the total number of rows currently known to TreeGrid.

      This method returns the actual total number of rows across the entire expanded tree only when TreeGrid uses a HierarchyFormat#FLATTENED data provider.

      For data providers that return data in HierarchyFormat#NESTED, hierarchy levels are discovered lazily – only when they appear in the viewport, which makes it impossible to determine the total number of rows in advance. As a result, this method may return a lower number that will gradually increase as more expanded rows have been seen.

      Overrides:
      getRowCount in class GridElement
      Returns:
      the number of rows
    • scrollToEnd

      public void scrollToEnd()
      Scrolls the TreeGrid to the end.