I have an android app which uses the uiautomator to click the options in a listview. The ListView looks like this:
I am trying to click the Full Benchmark list item, but my code for it does not recognize the list item. This is what I have:
UiScrollable listView = new UiScrollable(new UiSelector().scrollable(
true).className("android.widget.ListView"));
UiObject item1 = listView.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()),
"Full Benchmark");
item1.click();
I would appreciate any help!
Here is what I use to find, and then click an item in a listview:
//Find and click a ListView item
public void clickListViewItem(String name) throws UiObjectNotFoundException {
UiScrollable listView = new UiScrollable(new UiSelector());
listView.setMaxSearchSwipes(100);
listView.scrollTextIntoView(name);
listView.waitForExists(5000);
UiObject listViewItem = listView.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()), ""+name+"");
listViewItem.click();
System.out.println("\""+name+"\" ListView item was clicked.");
}
So in your case it would be
clickListViewItem("Full Benchmark")
Or:
UiScrollable listView = new UiScrollable(new UiSelector());
listView.setMaxSearchSwipes(100);
listView.scrollTextIntoView(name);
listView.waitForExists(5000);
UiObject listViewItem = listView.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()), "Full Benchmark");
listViewItem.click();
There are two approaches for the above said thing.
Approach 1:
UiCollection dummyList = new UiCollection(new UiSelector().className("android.widget.ListView").index(3));
UiObject dummyBenchmark = dummyList.getChildByText("Full Benchmark");
Approach 2:
new UiScrollable(
new UiSelector().scrollable(true)
).scrollIntoView(
new UiSelector().text("Full BenchMark")
);
new UiObject(
new UiSelector().text("Full BenchMark")
).click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With