gpt4 book ai didi

android-uiautomator - 如何使用 UIAutomator 在 Android 选项卡中滚动

转载 作者:行者123 更新时间:2023-12-01 14:19:15 27 4
gpt4 key购买 nike

我正在尝试使用 UIAutomator 滚动。场景是我进入选项卡中的“设置”菜单并单击“应用程序选项”,这会为我提供选项卡中所有应用程序的列表。现在我想滚动应用程序列表,这是我面临问题的地方。它滚动设置选项而不是应用程序列表。我附上了屏幕截图和我的代码。

            UiScrollable scroll = new UiScrollable(
new UiSelector().scrollable(true));
scroll.setAsVerticalList();

UiObject Apps = scroll.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()),
"Apps");
Apps.clickAndWaitForNewWindow();
UiObject Locker = scroll.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()),"Content Locker");
Locker.clickAndWaitForNewWindow();

Image

最佳答案

我也是 UiAutomator 的新手,没有太多的教程可以学习它。我在这里使用了 Smrti 示例,但是有些东西已经被弃用了,所以我对其进行了一些更正以使一切正常。这是我得到的

 UiDevice mDevice = UiDevice.getInstance(getInstrumentation());
mDevice.pressHome();

UiObject allAppsButton = mDevice
.findObject(new UiSelector().description("Apps"));

allAppsButton.clickAndWaitForNewWindow();

UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));

appViews.scrollIntoView(new UiSelector().text("Settings"));
mDevice.findObject(new UiSelector().text("Settings")).clickAndWaitForNewWindow();

mDevice.findObject(new UiSelector().text("Apps")).click();

我没有在此处包含对特定应用程序的搜索,我相信您可以像在我的代码片段中搜索“设置”应用程序一样管理它。

关于android-uiautomator - 如何使用 UIAutomator 在 Android 选项卡中滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20245299/

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