Appium元素定位(uiautomatorviewer)

一、uiautomatorviewer元素定位

1.adroid-sdk的安装目录tools下有1个自带的工具uiautomatorviewer,打开后,如下所示:

 点击后,如图所示:

步骤:

a.链接设备,打开APP

b.点击页面设备图标,刷新页面,与设备页面同步

c.点击需要定位的元素

d.在Node Detail模块,查看resource-id

 

二、元素定位方法

1.findElementById

例:el = driver.findElementById("android:id/title");

assertThat(el.getText(),equalTo("Add note"));

2.findElementByAccessibilityId

例:el = driver.findElementByAccessibilityId("menu_add_note_description");

assertThat(el.getText(),equalTo("node"));

3.findElementByCssSelector

4.findElementByLinkText

5.findElementByPartialLinkText

6.findElementByTagName

7.findEelementByXPath

例:el = driver.findElementByXPath("//android.widget.TextView[contains(@text,'Add note')]");

//el = driver.findElement(By.xpath("//android.widget.TextView"));

assertThat(el.getText(),equalTo("Add note"));

原文地址:https://www.cnblogs.com/ydnice/p/5787882.html