TextView - How to select other element?

This is my code:

 @FindBy(className = "android.widget.TextView")
 private MobileElement title;

 @FindBy(className = "android.widget.TextView")
 private MobileElement textMessage;

They are in the same LinearLayout. How do get the first and the second element?

xpath = “(//android.widget.TextView)[1]”
xpath = “(//android.widget.TextView)[2]”

1 Like
// version 1
@FindBy(className = "android.widget.TextView")
private List<MobileElement> textFields;

textFields.get(0) // first el
textFields.get(1) // second el

// version 2
    @AndroidBy(uiAutomator = "new UiSelector().className(\"android.widget.TextView\").instance(0)")
    private MobileElement title;

    @AndroidBy(uiAutomator = "new UiSelector().className(\"android.widget.TextView\").instance(1)")
    private MobileElement textMessage;
1 Like