Filter a List of Elements Using stringEquals

To test the <example-poll> component, we want to assert that there's one correct answer button, and that its text is UI Test Automation Model.

When you can't use a selector to get the elements you need, use an element filter.

For example, a selector can't access text nodes. To select elements based on text, filter a list of elements declaratively, without writing code.

An element with a filter must have a selector with returnAll set to true so that the generated method returns an array. (If a method returns a single element, you don't need a filter.)

In the filter, specify a method to apply to the element. Basic elements can apply basic actions. This example applies getText.

Then specify a matcher, which is applied to all the selected elements. Elements that match are returned by the generated method.

A matcher can filter based on its type. This tutorial uses a stringEquals matcher, which matches a string exactly, including whitespace and case equality. For the list of all matcher types, see Grammar: Matchers.

To select the correct button, test code simply calls the generated method and passes the string to check. The returned array contains only elements that match.

getButtonsByText('UI Test Automation Model');

Click Run Test.