Get List Item by Index
To get a list item by its index, write a selector
that accepts a number dynamically. The UTAM compiler generates a method that takes a number
parameter.
In the selector
, pass %d
to nth-of-type()
. This JSON selects all the th
elements that are children of the specified row in a tbody
.
"css": "tbody tr:nth-of-type(%d) > th",
nth-of-type()
is a CSS pseudo class. %d
is a selector parameter unique to UTAM, which gets a number at run time.
In JSON, use args
to define the name
and type
of the argument in the generated method. When using %d
, type
must be number
.
getRowHeader(rowIndex: number): Promise<(_BaseUtamElement)>;
The first cell in each row is a th
element. The test calls getRowHeader(ROW_INDEX)
to get the first cell in the fourth row and assert its text value.
The rest of the cells are td
elements. The test calls getRowCells(ROW_INDEX)
to get these cells and assert their text values.
Click Run Test.
Tip: If you declare an element as public, the value of name
becomes the method name, so choose something descriptive. If the selector returns all the elements, use a plural name like rowCells
, which becomes getRowCells
. If not, use a singular name like rowHeader
, which becomes getRowHeader
.