zoukankan      html  css  js  c++  java
  • Android 自动化测试经验 UiScrollable

    UiScrollable is a UiCollection and provides support for searching for items in a scrollable user interface (UI) elements. This class can be used with horizontally or vertically scrollable controls.

    UiScrollable是一个UiCollection(这东西还没搞懂),我们可以使用它,在可滑动的页面(水平滑动或上下滑动都可以)上查找我们想要的控件(item)。

    例1:下面的这个scrollClickObject方法就是使用UiScrollable,来自动选择我们想要点击的那个控件。

    public void scrollClickObject(String targetClassName,String targetName) throws UiObjectNotFoundException {
        UiScrollable collectionObject = new UiScrollable(new UiSelector().scrollable(true));
        if(collectionObject.exists()) {
            UiObject scrollableObject = collectionObject.getChildByText(new UiSelector().className(targetClassName), targetName);
            scrollableObject.clickAndWaitForNewWindow();
        } else {
            UiObject targetObject = new UiObject(new UiSelector().className(targetClassName).text(targetName));
            targetObject.clickAndWaitForNewWindow();
        }
    }

    首先定义一个UiScrollable对象,识别这个对象的唯一条件就是,屏幕上有可滑动的控件。(这里有一个问题,就是如果屏幕上同时存在2个可滑动的控件,就会报错了)

    然后我们判断这个可滑动对象是否存在

    • 存在,则使用getChildByText方法,获取我们想要点击的那个控件,然后点击它
    • 不存在,则说明页面不可滑动,也就是所有控件均已显示在界面上。那我们就可以直接使用UiObject获取控件并操作它。

    例2:

  • 相关阅读:
    yocto添加层简介
    ARM Linux 3.x的设备树(Device Tree)
    Linux device tree 简要笔记
    git 分支( branch ) 的基本使用
    Git 常用命令速查表(三)
    Git 常用命令详解(二)
    CentOS Linux安装python3
    R语言统计学习-1简介
    cnblog中添加数学公式支持
    我们数学中常用的自然常数e代表什么?看完长知识了!
  • 原文地址:https://www.cnblogs.com/rexmzk/p/2874203.html
Copyright © 2011-2022 走看看