python封装安卓查找元素方法V1.0
来源:互联网 发布:java date类 编辑:程序博客网 时间:2024/06/04 19:26
#coding=utf8from time import sleepfrom appium import webdriverimport osPATH = lambda p: os.path.abspath( os.path.join(os.path.dirname(__file__), p) )class appDriver(): def __init__(self,version=6.0): try: self.desired_caps = {} self.desired_caps ['platformName'] = 'Android' self.desired_caps ['platformVersion'] =version self.desired_caps ['deviceName'] ='PE-UL00' self.desired_caps ['app'] = PATH('../APK/xmlay.apk') self.appdriver= webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps ) except Exception,e: print "Driver Error:",e #根据“控件text属性的内容”构造出UiSelector对象 def app_find_element_by_text(self,text): try: item='new UiSelector().text('+"\""+text+"\""+')' #进行费时装换,如果不进行格式这步格式转换,会出现HTTP错误 item="%s" %(item) element=self.appdriver.find_element_by_android_uiautomator(item) return element self.appdriver.f except Exception,e: print "By Text Error:",e #根据“控件text属性包含的内容”构造出UiSelector对象 def app_find_elements_by_textContains(self,text): try: item='new UiSelector().textContains'+"("+text+")" item="%s" %(item) element=self.appdriver.find_elements_by_android_uiautomator(item) return element except Exception,e: print "By textContains Error:",e #根据“控件text属性正则表达式的内容”构造出UiSelector对象 def app_find_elements_by_textMatches(self,text): try: item='new UiSelector().textMatches'+"("+text+")" item="%s" %(item) element=self.appdriver.find_elements_by_android_uiautomator(item) return element except Exception,e: print "By textMatches Error:",e #根据“控件text属性开始的内容”构造出UiSelector对象 def app_find_elements_by_textStartsWith(self,text): try: item='new UiSelector().textStartsWith'+"("+text+")" item="%s" %(item) element=self.appdriver.find_elements_by_android_uiautomator(item) return element except Exception,e: print "By resourceId Error:",e #根据“控件content-desc属性的内容”构造出UiSelector对象 def app_find_element_by_description(self,text): try: item='new UiSelector().description'+"("+text+")" item="%s" %(item) element=self.appdriver.find_element_by_android_uiautomator(item) return element except Exception,e: print "By description Error:",e #根据“控件content-desc属性包含的内容”构造出UiSelector对象 def app_find_elements_by_descriptionContains(self,text): try: item='new UiSelector().descriptionContains'+"("+text+")" item="%s" %(item) element=self.appdriver.find_elements_by_android_uiautomator(item) return element except Exception,e: print "By descriptionContains Error:",e #根据“控件content-desc属性正则表达式的内容”构造出UiSelector对象 def app_find_elements_by_descriptionMatches(self,text): try: item='new UiSelector().descriptionMatches'+"("+text+")" item="%s" %(item) element=self.appdriver.find_elements_by_android_uiautomator(item) return element except Exception,e: print "By descriptionMatches Error:",e #根据“控件content-desc属性正则表达式的内容”构造出UiSelector对象 def app_find_elements_by_descriptionStartsWith(self,text): try: item='new UiSelector().descriptionStartsWith'+"("+text+")" item="%s" %(item) element=self.appdriver.find_elements_by_android_uiautomator(item) return element except Exception,e: print "By descriptionStartsWith Error:",e #根据资源resource-id获取对象 def app_find_element_by_resourceId(self,resourceid): try: item='new UiSelector().resourceId'+"("+resourceid+")" item="%s" %(item) element=self.appdriver.find_element_by_android_uiautomator(item) return element except Exception,e: print "By Text Error:",e #根据资源根据资源resource-id的正则表达式获取对象 def app_find_elements_by_resourceIdMatches(self,resourceid): try: item='new UiSelector().resourceIdMatches'+"("+resourceid+")" item="%s" %(item) element=self.appdriver.find_elements_by_android_uiautomator(item) return element except Exception,e: print "By resourceIdMatches Error:",e #根据资源根据资源class的正则表达式获取对象 def app_find_element_by_className(self,className): try: item='new UiSelector().className'+"("+className+")" item="%s" %(item) element=self.appdriver.find_element_by_android_uiautomator(item) return element except Exception,e: print "By resourceIdMatches Error:",e #根据资源根据资源index的正则表达式获取对象 def app_find_element_by_index(self,index): try: item='new UiSelector().index'+"("+index+")" # item="%s" %(item) element=self.appdriver.find_element_by_android_uiautomator(item) return element except Exception,e: print "By index Error:",e def quitApp(self): self.appdriver.quit() def test(): app=appDriver() try: sleep(5) el =app.app_find_element_by_text('允许') if el: el.click() except Exception,e: print e # try: #拨打电话和管理同话 sleep(5) el = app.app_find_element_by_text("禁止后不再询问") if el: el.click() sleep(5) el = app.app_find_element_by_text("始终允许") if el: el.click() except Exception,e: print e #访问SD卡 try: sleep(5) el = app.app_find_element_by_text("禁止后不再询问") if el: el.click() sleep(5) el = app.app_find_element_by_text("始终允许") if el: el.click() except Exception,e: print e #使用此设备的位置信息 try: sleep(5) el = app.app_find_element_by_text("禁止后不再询问") if el: el.click() sleep(5) el = app.app_find_element_by_text("始终允许") if el: el.click() except Exception,e: print e app.quitApp() if __name__=="__main__": test()
0 0
- python封装安卓查找元素方法V1.0
- 封装DOM查找元素方法
- python 字符串查找元素的方法
- python查找元素
- 查找安卓ANR触发点方法
- selenium(python)定位(查找)元素的方法小结
- XPath 元素查找方法
- jQuery元素查找方法
- 基于安卓的测绘计算软件V1.0使用说明
- 在Unity中常用到的一些安卓方法封装
- 安卓数据库封装
- 安卓Dialog封装
- 安卓OkHttp封装
- jquery查找元素方法示例
- js查找元素的方法
- lua查找表元素方法
- 数组查找最大元素方法
- 数组查找最小元素方法
- Win10 VS2015 caffe CUDA8.0 GTX1070安装指南
- MongoDB基本用法(增删改高级查询)
- 指针与内存
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentContr
- andorid 短信通知广播接收。
- python封装安卓查找元素方法V1.0
- HDU 5656 CA Loves GCD dp,常数优化
- oracle中如何将日期转成时间戳
- jQuery_如何用js或jQuery实现input失焦后,为空则为红色边框,不为空则为绿色边框?
- 原型设计模式
- 如何上传本地代码到git/coding
- MyEclipse配置输出控制台信息至文本文件中
- c# 委托与事件 学习笔记
- dos命令映射文件夹为虚拟磁盘分区