Appium + Python -------------元素定位

时间:2016-05-06 10:38:45   收藏:0   阅读:2006

说在前面

1、https://github.com/appium/python-client/tree/master/test  里面有一些test ,可以看看,研究研究

2、学会使用 uiautomatorviewer 和 hierarchyviewer  ,这两个工具可以帮助查看app一些信息,非常好用,在android-tools下

 

 

 

控件的特征就是控件的属性,所以我们可以根据控件的特征进行定位

PS:断言部分之后再细说

1、find_elements_by_accessibility_id,以accessibility_id进行定位,对Android而言,就是content-description属性(使用uiautomatorviewer 可以查看到) ,所以参数不要弄错

  

el = self.driver.find_element_by_accessibility_id(u请输入QQ号码或手机或邮箱) #以QQ登录页为例
 self.assertIsNotNone(el)

els = self.driver.find_elements_by_accessibility_id(请输入QQ号码或手机或邮箱)
self.assertIsInstance(els, list)

 

2、find_element_by_class_name,根据class进行定位

 self.driver.find_element_by_class_name("android.widget.EditText")  # 定位唯一元素
 self.driver.find_elements_by_class_name("android.widget.EditText")[0]  # 找到所有android.widget.EditText并定位第一个

 

3、find_elemnt_by_name ,根据name进行定位,对于android来说,就是text属性

e3 = self.driver.find_element_by_name(u"登 录")

 

4、find_element_by_android_uiautomator ,使用uiautomator定位,后面参数更改即可

  还有UiSelector.descriptionMatches   、   UiSelector.descriptionStartWith   、UiSelector.description

 

5、driver.find_element_by_id 与 UiSeletor.resourceId  都是通过resourceId 来进行定位,这个属性只有在Api Level18以上才有

e9 = self.driver.find_element_by_android_uiautomator(new Uiseletor()
                                                             .resourceId
                                                             ("com.taobao.qianniu:id/accountCompleteTextView"))
e10 = self.driver.find_element_by_id("com.taobao.qianniu:id/accountCompleteTextView")

 

--------如果上面说的有什么问题,麻烦大家及时扣扣我!感恩!

--------会不定时更新,转载请说明原文

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!