如何到达appium滚动条的末端? [英] How to reach the end of a scroll bar in appium?

查看:252
本文介绍了如何到达appium滚动条的末端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动执行水平条的滚动,其中水平条的元素是动态的,并且可以从API中获取.

I'm trying to automate scrolling of a horizontal bar,where the elements of the bar are dynamic and are getting fetched from an API.

有没有一种方法可以自动在appium中使用它?

Is there a way to automate it in appium?

推荐答案

如果页面底部有任何元素或文本,则可以使用UiAutomator2.

If you have any element or text in the bottom of page then you can use UiAutomator2.

如果要使用appium,请添加所需的功能'UiAutomator2'.

add in desired capability 'UiAutomator2' if you are using appium.

capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");

如果您具有元素的ID,请现在使用以下函数

Now use below functions if you have element's 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();
        }
    }

如果您有元素的文本,请使用它.

Use this if you have element's text.

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();
        }
    }

如果您不知道botton中的任何元素,则必须使用屏幕尺寸

If you don't know any element in botton then you have to use screen size

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();
    }

这篇关于如何到达appium滚动条的末端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆