一、uiautomatorviewer元素定位

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

Appium元素定位(uiautomatorviewer)

 点击后,如图所示:

Appium元素定位(uiautomatorviewer)

步骤:

a.链接设备,打开APP

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

c.点击需要定位的元素

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

Appium元素定位(uiautomatorviewer)

 

Appium元素定位(uiautomatorviewer)

二、元素定位方法

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"));

 

相关文章:

  • 2021-08-24
  • 2021-11-13
  • 2021-06-30
  • 2021-10-09
  • 2021-09-27
  • 2018-12-04
  • 2021-06-02
  • 2021-10-07
猜你喜欢
  • 2022-01-14
  • 2021-09-23
  • 2020-06-20
  • 2021-10-06
  • 2021-12-18
  • 2021-08-13
  • 2022-01-16
相关资源
相似解决方案