gpt4 book ai didi

java - 无法使用 UIScrollable 和 UISelector 定位元素

转载 作者:行者123 更新时间:2023-12-02 02:26:40 25 4
gpt4 key购买 nike

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

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)

最佳答案

UIScrollable 的公共(public)构造函数是:

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

关于java - 无法使用 UIScrollable 和 UISelector 定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57249281/

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