• Appium学习笔记4_元素定位方法


             Appium之元素定位,如果对Android上如何使用工具获取页面元素有问题的,请转战到这:http://www.cnblogs.com/taoSir/p/4816382.html

             下面主要是针对自己的了解和学习,简单的总结下关于Appium native APP上的一些元素定位方法的使用以及通过UI Automator Viewer定位页面以后,如果从上面定位到你想使用的元素。

             已淘宝为例,来进行元素的定位。打开UI Automator Viewer

    Appium1

     

    Appium和Webdriver有一点区别在元素定位的方法上,见下面代码:

    //有点需要注意的是,findElementByAccessibilityId在Selenium上是不带这个方法的,所以只能用Appium提供的封装方法
                driver.findElementByAccessibilityId(""); //Selenium不带这个方法
                //下面的形式Appium都能使用
                driver.findElementByClassName("calssName"); 
              driver.findElement(By.className("className"));

    FindElement By ID

    针对taobao,购物车的定位。

    通过ID定位,打开UI Automator Viewer, node detail下找到标签是“resource-id”—>”com.taobao.taobao:id/tv_title”

    driver.findElementById("com.taobao.taobao:id/tv_title");

    FindElement By Classname

    针对taobao,购物车的定位:

    通过classname定位(一般情况下,最好不要通过classname来进行元素的定位,避免出现重复),打开UI Automator Viewer, node detail下找到标签是“class”—>“android.widget.TextView”

    driver.findElementByClassName("android.widget.TextView");

    FindElement By Name

    针对taobao,购物车的定位:

    通过name定位,打开UI Automator Viewer, node detail下找到标签是“text”—>“购物车”

    driver.findElementByName("购物车");

    FindElement By Accessibility Id

    针对谷歌浏览器打开的百度首页,搜索按钮的定位:

    通过AccessibilityId定位,打开UI Automator Viewer, node detail下找到标签是“content-desc”—>“百度一下”

    driver.findElementByAccessibilityId("百度一下");

    Appium2

  • 相关阅读:
    hdu 4786 Fibonacci Tree
    Sae 上传文件到Storage
    Java通过代理server上网
    iOS 利用Socket UDP协议广播机制的实现
    android_handler(三)
    shell 脚本执行日志通用模块
    adt-bundle-linux-x86_64-20131030下新建project提示找不到adb和R.java问题的解决
    【MongoDB】The Access control of mongodb
    Java——设计模式(装饰模式_IO)
    动态顺序表
  • 原文地址:https://www.cnblogs.com/taoSir/p/4832454.html
Copyright © 2020-2023  润新知