在我的移动应用程序自动化框架中,我无法在Appium android中滚动和选择元素。?

在我的移动应用程序自动化框架中,我无法在Appium android中滚动和选择元素。?,android,mobile,ui-automation,appium-android,android-uiautomator,Android,Mobile,Ui Automation,Appium Android,Android Uiautomator,。此代码将选择元素,但不会滚动到确切的元素并选择值。请帮助我修改此代码 public void applyBedTimefromdate() throws InterruptedException { MobileElement element = (MobileElement) driver .findElementsByAndroidUIAutomator( "new UiScrollable(new UiSe

。此代码将选择元素,但不会滚动到确切的元素并选择值。请帮助我修改此代码

public void applyBedTimefromdate() throws  InterruptedException {
MobileElement element = (MobileElement) driver
                .findElementsByAndroidUIAutomator(
                        "new UiScrollable(new UiSelector().resourceId(\"com.hdc:id/hour\")).getChildByText("
                                + "new UiSelector().className(\"android.view.View[@index='0']\"), \"3\"));");
        element.click();
}

我们可以尝试使用UiAutomator2按文本滚动

如果您正在使用appium,请添加所需的功能“UiAutomator2”

capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
现在试试下面的代码

public void scrollByText(String menuText) {

        try {

             driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textMatches(\"" + menuText + "\").instance(0));")); 
        } catch (Exception e) {
           e.printStackTrace();
        }
    }
如果您有元素id(资源id),请使用以下函数


您好,Mussamil,我已将您的代码应用到我的程序中,但它不起作用。此页面有几个带有滚动选项的元素。我想先单击该项目,然后滚动到所需的值。谢谢此功能仅用于滚动而不是单击。如果需要,您必须先单击。只需将文本传递到您想要滚动的位置,即单击后滚动10或11。如果scroll不起作用,那么我们可以进一步讨论。是的,我尝试了scroll的此功能。但我不会滚动我的元素。请检查我的图像以了解情况。您可以尝试此驱动程序。findElement(MobileBy.AndroidUIAutomator(“new UiScrollable(new UiSelector().resourceIdMatches(\“*id/id OF YOUR LOCATOR\”)))。flingForward());将“定位器ID”替换为“定位器ID”
 public void scrollByID(String Id, int index) {

        try {

             driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId(\""+Id+"\").instance("+index+"));")); 

        } catch (Exception e) {
           e.printStackTrace();
        }
    }