gpt4 book ai didi

android uiautomator点击ListView

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:15:51 25 4
gpt4 key购买 nike

我有一个 android 应用程序,它使用 uiautomator 单击 ListView 中的选项。 ListView 看起来像这样:

enter image description here

我正在尝试单击“完整基准测试”列表项,但我的代码无法识别该列表项。这是我的:

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();

如有任何帮助,我将不胜感激!

最佳答案

这是我用来查找然后单击 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.");
}

所以在你的情况下会是

clickListViewItem("Full Benchmark")

或者:

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();

关于android uiautomator点击ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16992165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com