Detox uses matchers to match UI elements in your app.
Note: For best results, it is recommended to match elements by unique identifiers. Matching by text or labels can introduce test flakiness when your app’s text change or when changing your app’s localization.
Match elements with the specified accessibility identifier. In React Native, this corresponds to the value in the
Match elements with the specified accessibility label (iOS) or content description (Android). In React Native, this corresponds to the value in the
Match elements with the specified text.
Matches elements whose class is, or inherits from, the specified class name. On Android, provide the class canonical name.
Note: iOS and Android class names differ.
element(by.type('RCTImageView')); //iOS class name
element(by.type('android.widget.ImageView')); //Android class canonical name
by.traits([traits]) iOS Only
Matches elements by their accessibility traits.
Currently supported values:
Matches elements with an ancestor that matches the specified matcher.
Matches elements with at least one descendant that matches the specified matcher.
Matches elements by combining several matchers together.
If a matcher resolves into multiple matched UI elements, you may specify which element to use by its index.
On iOS, matched elements are sorted by their x and y axes.
Note: Due to different underlying implementations of Detox on iOS and Android, as well as other differences in the OS implementations, as well as RN implementation differences on each OS, indices may not match between iOS and Android. Relying on indices may also introduce flakiness in your tests as your app’s user interface is updated. It is recommended to use unique identifier matchers for your elements.