Appium入门(8)__控件定位

部分摘自:http://www.testclass.net/appium/appium-base-find-element/

 

appium 通过 uiautomatorviewer.bat 工具来查看控件的属性。该工具位于 Android SDK/tools/目录下。

如果目标设备的API Level低于18则UIAutomatorViewer不能获得对应的Resource ID,只有等于大于18的时候才能使用。

打开uiautomatorviewer.bat后同步设备屏幕

 

id定位:driver.findElement(By.id(''))

name定位:driver.findElement(By.name("99"))   #text就是要找的name

class定位:WebElement button=driver.findElement(By.className("android.widget.Button"))

xpath定位:当果如果出现class 相同的情况下可以用控件的属性值进行区分

     driver.findElement(By.xpath("android.widget.Button[contains(@text,'7')]")).click()

 

posted @ 2018-01-31 15:25  happy_xiaoxiao  Views(168)  Comments(0Edit  收藏  举报