zoukankan      html  css  js  c++  java
  • robotium 中的组件Class By获取web元素的方法

    robotium中的组件Class By

    Class By继承了java.lang.Object 类,用于获取页面元素对象 可以通过元素的类名、css选择器、id、元素名、标签名、文本内容、绝对路径 获取

    例如By.id("note"),同过布局文件中的android:id="@+id/note"获取元素,这个id值会在R.java中注册

    要注意的是:By.id("note")返回的是一个对象,其它方法也是返回WebElement对象,要通过父类的toString()返回对象的字符串表示形式。

    Class By也提供了方法getValue(),这个方法是干嘛用的呢?

    反编译robotium的jar查看源码,我们知道By本身是个抽象类,

    By.id()方法其实是返回嵌套类Id的一个对象,要获取id值还要调用方法getValue()

    嵌套类Id有一个getValue()方法,返回id

    By.id("note").getValue() 返回String类型的id

     static class Id extends By  {

      private final String id;

      public String getValue()   {    return id;   }

      public Id(String id)   {    this.id = id;   }  }

    By类自身也有个getValue(),不过返回空

    public String getValue()  {   return "";  }

  • 相关阅读:
    java移位的具体应用
    mysql计划任务(轮询执行脚本)
    算法题(1)
    transient关键字及Serializable的序列化与反序列化
    java后台调用短信接口,实现发送短信验证码的控制层实现
    防卫导弹
    C++ STL
    字母转换
    三分·三分求极值
    各种数据类型取值范围
  • 原文地址:https://www.cnblogs.com/zhitang2009/p/3424800.html
Copyright © 2011-2022 走看看