通过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\")");