Automation scrollIntoView在日志滚动视图的应用程序中不工作。在一次/两次滑动后不会引发此类元素异常

Automation scrollIntoView在日志滚动视图的应用程序中不工作。在一次/两次滑动后不会引发此类元素异常,automation,appium-android,vertical-scroll,Automation,Appium Android,Vertical Scroll,滚动的通用功能,其中scrollablelist是滚动视图的定位器,我们必须在其中滚动 public void scrollToElementWithText(RemoteWebDriver driver, String scrollableList, String text) { MobileElement element = (MobileElement) driver .findElement(MobileBy.AndroidUIAutom

滚动的通用功能,其中scrollablelist是滚动视图的定位器,我们必须在其中滚动

public void scrollToElementWithText(RemoteWebDriver driver, String scrollableList, String text) {

        MobileElement element = (MobileElement) driver
                .findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().resourceId(\""
                        + scrollableList + "\")).scrollIntoView(" + "new UiSelector().text(\"" + text + "\"))"));
    }

您可以在下面的代码中使用现有代码
可滚动(true)。实例(0))

如果您将
appium
用作
automation
引擎,请添加所需的功能
UiAutomator2

capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
现在,若您有元素的id,并且索引为0,那个么请使用下面的函数,因为页面上只有一个元素

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();
        }
    }
使用文本滚动

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();
        }
    }
使用屏幕大小帮助滚动:

public void scrollToBottom() {

      int  x = driver.manage().window().getSize().width / 2;
      int start_y = (int) (driver.manage().window().getSize().height * 0.2);
      int end_y = (int) (driver.manage().window().getSize().height * 0.8);
        TouchAction dragNDrop = new TouchAction(driver)
                        .press(PointOption.point(x,start_y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))
                        .moveTo(PointOption.point(x, end_y))
                        .release();
        dragNDrop.perform();
    }

抱歉键入,它的长滚动视图。相同的问题..尝试了scrollByText..它在几次滑动后停止,并且没有引发此类元素异常。更新了答案,请检查最后一个解决方案。它只是滚动,所以滚动后,您可以执行所需的行动