【问题标题】:Unable to locate element using UIScrollable and UISelector无法使用 UIScrollable 和 UISelector 定位元素
【发布时间】:2019-07-29 07:47:39
【问题描述】:

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

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)

【问题讨论】:

    标签: java appium scrollable


    【解决方案1】:

    UIScrollable 的公共构造函数是:

    UiScrollable(UiSelector container);
    

    使用UiSelector 的公共方法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

    【讨论】:

    • @shreyashshukla 很高兴为您提供帮助。您能否将答案评为有用。谢谢
    猜你喜欢
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    • 2021-08-19
    • 2016-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多