Skip to content

Grid

flaui.core.automation_elements.Grid

Bases: AutomationElement

Element for grids and tables

column_count property

Gets the total column count.

Returns:

Type Description
int

Column Count

column_headers property

Gets all column header elements.

Returns:

Type Description
List[AutomationElement]

List of column header elements

header property

Gets the header item.

Returns:

Type Description
GridHeader

Header item

row_count property

Gets the total row count.

Returns:

Type Description
int

Row Count

row_headers property

Gets all row header elements.

Returns:

Type Description
List[AutomationElement]

List of row header elements

row_or_column_major property

Gets whether the data should be read primarily by row or by column.

Returns:

Type Description
RowOrColumnMajor

Row/Column

rows property

Returns the rows which are currently visible to UIA. Might not be the full list (eg. in virtualized lists)! /// Use "GetRowByIndex" to make sure to get the correct row.

Returns:

Type Description
List[GridRow]

List of GridRow elements

selected_item property

Gets the first selected item or null otherwise.

Returns:

Type Description
GridRow

GridRow element if selected, else None

selected_items property

Gets all selected items.

Returns:

Type Description
List[GridRow]

List of GridRow elements

add_to_selection(row_index=None, column_index=None, text_to_find=None)

add_to_selection(
    row_index: int,
    column_index: None = None,
    text_to_find: None = None,
) -> "GridRow"
add_to_selection(
    row_index: None = None,
    column_index: int = ...,
    text_to_find: str = ...,
) -> "GridRow"

Add a row to the selection by index or by text in the given column.

Parameters:

Name Type Description Default
row_index Optional[int]

Row index

None
column_index Optional[int]

Column index

None
text_to_find Optional[str]

Text to find in the column

None

Returns:

Type Description
GridRow

GridRow element

Raises:

Type Description
ValueError

On invalid input combination

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def add_to_selection(
    self, row_index: Optional[int] = None, column_index: Optional[int] = None, text_to_find: Optional[str] = None
) -> GridRow:
    """Add a row to the selection by index or by text in the given column.

    :param row_index: Row index
    :param column_index: Column index
    :param text_to_find: Text to find in the column
    :raises ValueError: On invalid input combination
    :return: GridRow element
    """
    if all([column_index, text_to_find]):
        return GridRow(
            raw_element=self._retry_while_null_reference_exception(
                lambda: self.raw_element.AddToSelection(column_index, text_to_find),
                "Row not found in column, cannot add to selection",
            )
        )
    elif all([row_index]) and not any([column_index, text_to_find]):
        return GridRow(
            raw_element=self._retry_while_null_reference_exception(
                lambda: self.raw_element.AddToSelection(row_index),
                "Row not found in row index, cannot add to selection",
            )
        )
    else:
        raise ValueError("Invalid input sent to the function, cannot add to the selection")

get_row_by_index(row_index)

a row by index.

Parameters:

Name Type Description Default
row_index int

Row index

required

Returns:

Type Description
GridRow

GridRow element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def get_row_by_index(self, row_index: int) -> GridRow:
    """a row by index.

    :param row_index: Row index
    :return: GridRow element
    """
    return GridRow(raw_element=self.raw_element.GetRowByIndex(row_index))

get_row_by_value(column_index, value)

Get a row by text in the given column.

Parameters:

Name Type Description Default
column_index int

Column index

required
value str

Value

required

Returns:

Type Description
GridRow

GridRow element

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def get_row_by_value(self, column_index: int, value: str) -> GridRow:
    """Get a row by text in the given column.

    :param column_index: Column index
    :param value: Value
    :return: GridRow element
    """
    return GridRow(raw_element=self.raw_element.GetRowByValue(column_index, value))

get_rows_by_value(column_index, value, max_items=0)

Get all rows where the value of the given column matches the given value.

Parameters:

Name Type Description Default
column_index int

The column index to check.

required
value str

The value to check.

required
max_items int

Maximum numbers of items to return, 0 for all, defaults to 0

0

Returns:

Type Description
List[GridRow]

List of found rows as GridRow elements.

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def get_rows_by_value(self, column_index: int, value: str, max_items: int = 0) -> List[GridRow]:
    """Get all rows where the value of the given column matches the given value.

    :param column_index: The column index to check.
    :param value: The value to check.
    :param max_items: Maximum numbers of items to return, 0 for all, defaults to 0
    :return: List of found rows as GridRow elements.
    """
    return [GridRow(raw_element=_) for _ in self.raw_element.GetRowsByValue(column_index, value, max_items)]  # type: ignore

remove_from_selection(row_index=None, column_index=None, text_to_find=None)

remove_from_selection(
    row_index: int,
    column_index: None = None,
    text_to_find: None = None,
) -> "GridRow"
remove_from_selection(
    row_index: None = None,
    column_index: int = ...,
    text_to_find: str = ...,
) -> "GridRow"

Remove a row to the selection by index or by text in the given column.

Parameters:

Name Type Description Default
row_index Optional[int]

Row index

None
column_index Optional[int]

Column index

None
text_to_find Optional[str]

Text to find in the column

None

Returns:

Type Description
GridRow

GridRow element

Raises:

Type Description
ValueError

On invalid input combination

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def remove_from_selection(
    self, row_index: Optional[int] = None, column_index: Optional[int] = None, text_to_find: Optional[str] = None
) -> GridRow:
    """Remove a row to the selection by index or by text in the given column.

    :param row_index: Row index
    :param column_index: Column index
    :param text_to_find: Text to find in the column
    :raises ValueError: On invalid input combination
    :return: GridRow element
    """
    if all([column_index, text_to_find]):
        return GridRow(
            raw_element=self._retry_while_null_reference_exception(
                lambda: self.raw_element.RemoveFromSelection(column_index, text_to_find),
                "Row not found in column, cannot remove from selection",
            )
        )
    elif all([row_index]) and not any([column_index, text_to_find]):
        return GridRow(
            raw_element=self._retry_while_null_reference_exception(
                lambda: self.raw_element.RemoveFromSelection(row_index),
                "Row not found in row index, cannot remove from selection",
            )
        )
    else:
        raise ValueError("Invalid input sent to the function, cannot remove from the selection")

select(row_index=None, column_index=None, text_to_find=None)

select(
    row_index: int,
    column_index: None = None,
    text_to_find: None = None,
) -> "GridRow"
select(
    row_index: None = None,
    column_index: int = ...,
    text_to_find: str = ...,
) -> "GridRow"

Select the first row by text in the given Row index or a combination of Column index along with text_to_find.

Parameters:

Name Type Description Default
row_index Optional[int]

Row index

None
column_index Optional[int]

Column index

None
text_to_find Optional[str]

Text to find in the column

None

Returns:

Type Description
GridRow

GridRow element

Raises:

Type Description
ValueError

On invalid input combination

Source code in flaui/core/automation_elements.py
@handle_csharp_exceptions
def select(
    self, row_index: Optional[int] = None, column_index: Optional[int] = None, text_to_find: Optional[str] = None
) -> GridRow:
    """Select the first row by text in the given Row index or a combination of Column index along with text_to_find.

    :param row_index: Row index
    :param column_index: Column index
    :param text_to_find: Text to find in the column
    :raises ValueError: On invalid input combination
    :return: GridRow element
    """
    if all([column_index, text_to_find]):
        return GridRow(
            raw_element=self._retry_while_null_reference_exception(
                lambda: self.raw_element.Select(column_index, text_to_find), "Row not found in column"
            )
        )
    elif all([row_index]) and not any([column_index, text_to_find]):
        return GridRow(
            raw_element=self._retry_while_null_reference_exception(
                lambda: self.raw_element.Select(row_index), "Row not found in row index"
            )
        )

    else:
        raise ValueError("Invalid input sent to the function, cannot select the row")