无法使用UIScrollable和UISelector定位元素

时间:2019-07-29 07:47:39

标签: java appium scrollable

我正在使用此代码选择元素

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)

1 个答案:

答案 0 :(得分:0)

UIScrollable的公共构造函数是:

UiScrollable(UiSelector container);

使用className中的公共方法UiSelector,例如:

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