无法使用 UIScrollable 和 UISelector 定位元素

Unable to locate element using UIScrollable and UISelector

我将此代码用于 select 元素

public static void swipe()
{

    MobileElement element = driver.findElementByAndroidUIAutomator(
                    "new UiScrollable(new UiSelector().class(\"android.widget.ImageView\")).getChildByText("
                    + "new UiSelector().resourceId(\"com.spotify.music:id/title\"), \"UnderCover\")");

    //Perform the action on the element
    System.out.println(element.getText()); //This would print - Unblock Me FREE
}

我收到这个错误

io.appium.uiautomator2.common.exceptions.UiSelectorSyntaxException: Could not parse expression `new UiScrollable(new UiSelector().class("android.widget.ImageView")).getChildByText(new UiSelector().resourceId("com.spotify.music:id/title"), "UnderCover")`: UiScrollable has no suitable constructor with arguments [new UiSelector().class("android.widget.ImageView")]
at io.appium.uiautomator2.utils.UiExpressionParser.findConstructor(UiExpressionParser.java:232)

Public UIScrollable 的构造函数是:

UiScrollable(UiSelector container);

使用 UiSelector 的 Public 方法 className 例如:

UiSelector className (String className); //or UiSelector className (Class<T> type);

尝试

new UiScrollable(new UiSelector().className("android.widget.ImageView"));

而不是

new UiScrollable(new UiSelector().class("android.widget.ImageView"));

参考官方文档:https://developer.android.com/reference/android/support/test/uiautomator/UiSelector#classes