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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM