Get List Items by Pattern
To use a pattern to select items from a list, write a selector
that accepts a string dynamically. The UTAM compiler generates a method that takes a parameter.
In the selector
, pass %s
to nth-of-type()
.
nth-of-type()
is a CSS pseudo class. %s
is a selector parameter that's unique to UTAM and gets a string at run time.
"css": "li:nth-of-type(%s)"
In JSON, use args
to define the name
and type
of the argument. When using %s
, type
must be string
.
A pattern can return multiple elements so add "returnAll": true
. The generated method returns an array.
getListItemsByPattern(pattern: string): Promise<(_BaseUtamElement)[]>;
In test code, the pattern
parameter can be the string odd
or even
, or the pattern <An+B>
, which matches every element whose index is found in the pattern.
A
—integer step sizeB
—integer offsetn
—all positive integers, starting from 0.
For more information, see the nth-of-type()
syntax at MDN.
The test code calls getListItemsByPattern('odd')
to get the odd elements from the list. It also calls getListItemsByPattern('3n')
, which gets every third element.
Click Run Test.