@AndroidFindBy(uiAutomator = "new UiSelector().text(\"my text\")")
when I need to find the elements by text and I’m sure that no other element with the same text exist in the page.
also you could try something like
@AndroidFindBy(id = "yourID")
public List<MobileElement> element;
and then use element.get(elementIndex).click();
I’m not using the index shown in the inspector. First element in the page from top to bottom has index 0, second element has index 1 and so on.
Sometimes I encounter errors when I used the index from the inspector
There are 2 elements that have the same text: a title element and the value element. Is there a way to select the 2nd element that has that text?
Regading your 2nd method:
@AndroidFindBy(id = “yourID”)
public List element;
element.get(elementIndex).click();
I was using that method…but some of the elements are off screen so when you create your list it can’t see them and doesn’t add them to the list. So maybe only the top 4 elements are included in the list but the other 6 that are off screen are not included.
new UiSelector().resourceIdMatches(\".*:id/people_form_recyclerview\")
instead of “First Name” use variable
function WebElement getElementByText(String text)
return driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().resourceIdMatches(\".*:id/people_form_recyclerview\")).getChildByText("
+ "new UiSelector().resourceIdMatches(\".*:id/formElementValue\"), \"" + text + "\")"));