zoukankan      html  css  js  c++  java
  • 【基础】查找元素篇(二)

    通过uiautomatorviewer工具来定位

    一、通过ID(resource-id)

    示例:

    driver.findElement(By.id("com.globalegrow.app.gearbest:id/show_shop_price"));

    driver.findElementById(id"com.globalegrow.app.gearbest:id/show_shop_price")

    二、通过className(class)

    示例:

    driver.findElement(By.className("android.widget.TextView"));

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

    这个一般用复数来获取,然后用List来取值。

    三、通过xpath

    driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'Cart')]"));

    android.widget.TextView 为class

    四、通过AccessibilityId(content-desc)

    driver.findElementByAccessibilityId("test");

    五、通过AndroidUIAutomator

    5.1 text
    driver.findElementByAndroidUIAutomator("new UiSelector().text("more+")");
    5.2 textContains
    driver.findElementByAndroidUIAutomator("new UiSelector().textContains("more")");
    5.3 index,多个
    driver.findElementByAndroidUIAutomator("new UiSelector().textContains("more").index(1)");
    5.4 包名,id
    driver.findElementByAndroidUIAutomator("new UiSelector().className("android.widget.TextView").resourceId("com.globalegrow.app.gearbest:id/more_deals_tv")");

    5.5 desc

    driver.findElementByAndroidUIAutomator("new UiSelector().description("test")");

  • 相关阅读:
    盒子模型中问题
    outline
    高度自动相等方法
    正则表达式
    绝对定位 相对定位
    replace 使用函数作为第二参数
    float 浮动
    line-height 行高
    元素隐藏
    现代浏览器内部
  • 原文地址:https://www.cnblogs.com/Jourly/p/8080206.html
Copyright © 2011-2022 走看看