#coding=utf8
from time import sleep
from appium import webdriver
import os
PATH = 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+")"
python封装安卓查找元素方法V1.0
最新推荐文章于 2022-12-12 23:49:39 发布
这个Python类封装了使用Appium针对Android设备的元素查找方法,包括通过text、textContains、textMatches、textStartsWith、description、descriptionContains、descriptionMatches、descriptionStartsWith、resourceId和index等属性进行定位。提供了点击元素的功能,并针对权限设置进行了示例测试。
摘要由CSDN通过智能技术生成