Commands that interact with a view (e.g tapOn, assertVisible, copyTextFrom) require the view to be specified using using a selector.
There are many different selectors available:
- tapOn:# or any other command that works with selectorstext:Text# (optional) Finds element with text or accessibility text that matches regepid:id# (optional) Finds element with accessibility identifier that matches regexpindex:0# (optional) 0-based index of the view to select among those that match all other criteriapoint:50%, 50%# (optional) Relative position on screen. "50%, 50%" is the middle of screenpoint:50, 75# (optional) Exact coordinates on screen. x:50 y:50, in pixelswidth:100# (optional) Finds element of a given widthheight:100# (optional) Finds element of a given heighttolerance:10# (optional) Tolerance to apply when comparing width and heightenabled:true# (optional) Searches for view with a given "enabled" statechecked:true# (optional) Searches for view with a given "checked" statefocused:true# (optional) Searches for view with a given "focused" stateselected:true# (optional) Searches for view with a given "selected" state
Shorthand selector for text
If you want to use the text selector, you can use the following shorthand:
- tapOn:Text# or any other command that works with selectors
Relative position selectors
Apart from the selectors mentioned above, Maestro is also able to select views using their relative position (i.e. "below another view", or "contains child"):
- tapOn:# or any other command that works with selectorsbelow:View above that has this text# matches a view *above* that has the given textabove:id:view_below_id# matches a view *below* that has the given idleftOf:View to the right has this textrightOf:View to the left has this textcontainsChild:Text in a child view# matches a view that has a *direct* child view with the given textchildOf:# matches a view that is a child of a view with id "buy-now"id:buy-nowcontainsDescendants:# matches a view that has all the descendant views given below - id:title_idtext:A descendant view has id "title_id" and this text - Another descendant view has this text
Selecting one view among many similar
If you have multiple views matching the same selector (i.e. many views with text Hello), use index parameter to specify which one to select exactly. For example, the following command will pick the 3rd view that has text Hello: