UiAutomator Locator Strategy
The UiAutomator2 driver enables element lookup using UiSelector and UiScrollable locator types, which are natively supported by the UI Automator framework. These locators allow for flexible ways to reference complicated element paths, and their performance is very close to native.
The driver enables the use of locator types via the -android uiautomator
locator strategy.
Warning
Google is going to remove
the UiScrollable and UiSelector classes from the UiAutomator framework. If you use these locators to
scroll, see the Migrating from UiScrollable and UiSelector guide. For
element lookup, prefer the predicate string and class chain strategies instead,
which are equally as fast.
Examples¶
Note that the index selector is unreliable so prefer instance instead. The following examples are written against the ApiDemos application using Ruby.
-
Find the first textview:
-
Find the first element by text:
-
Find the first scrollable element, then find a
TextViewwith the textTabs. TheTabselement will be scrolled into view. -
As a special case,
scrollIntoViewreturns the element that is scrolled into view. It allows scrolling to anyUiSelector.