python封装安卓查找元素方法V1.0

这个Python类封装了使用Appium针对Android设备的元素查找方法,包括通过text、textContains、textMatches、textStartsWith、description、descriptionContains、descriptionMatches、descriptionStartsWith、resourceId和index等属性进行定位。提供了点击元素的功能,并针对权限设置进行了示例测试。
摘要由CSDN通过智能技术生成
#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+")"
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WEL测试

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值