scrollIntoView无法在appium中用于日志滚动视图。一两次滑动后不会抛出此类元素异常

问题描述 投票:0回答:1

滚动的通用函数,其中 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 + "\"))"));
    }
automation appium-android vertical-scroll
1个回答
0
投票

您可以尝试使用现有代码scrollable(true).instance(0))中的以下代码

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

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();
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.