Filter a List of Elements Using stringContains
In this tutorial, we want to assert that the poll component contains two buttons with text that contains the word Model
.
Remember, when you can't use a selector
to get the elements you need, use an element filter
.
This filter
applies the getText
method to the selected elements.
It then applies the stringContains
matcher
, which checks each element to see whether its text contains a specified string. The check includes case equality.
The name
property in the matcher's args
array becomes the argument in the generated method, so provide a meaningful name.
getButtonsContain(text: string): Promise<(_BaseUtamElement)[]>;
To select the button elements that contain the string Model
, test code calls the generated method and passes the string to check. The returned array contains only elements that match.
getButtonsContain('Model');
Click Run Test.