Appium python+appium 重写元素定位的方法

沈伟-测试前行者 · 2017年11月06日 · 743 次阅读

在实际使用 appium 的过程中,元素定位是必不可少的一步,但是为了装个懒子,也为了看起来更加的美观,也为了省事,所以还是对这些定位方式做一下封装吧
而且有一个好处就是,如果在实际运行过程中,自己的定位出现问题,也能及时发现

# 重写元素定位的方法
class Action(object):
# 初始化
def init(self, se_driver):
self.driver = se_driver

# 通过 resource-i 定位
def findId(self, id):
try:
f = self.driver.find_element_by_id(id)
return f
except Exception as e:
print("未找到%s"%(id))

# 通过 class 定位
def findClassName(self, name):
try:
f = self.driver.find_element_by_class_name(name)
return f
except Exception as e:
print("未找到%s"%(name))

# 通过 text 定位
def findAU(self, name):
try:
f = self.driver.find_element_by_android_uiautomator('text(\"' + name +'\")')
return f
except Exception as e:
print("未找到%s"%(name))

# 通过 xpath 定位
def findXpath(self, xpath):
try:
f = self.driver.find_element_by_xpath(xpath)
return f
except Exception as e:
print("未找到%s"%(xpath))

# 通过 content-desc
def findAI(self, content_desc):
try:
f = self.driver.find_element_by_accessibility_id(content_desc)
return f
except Exception as e:
print("未找到%s"%(content_desc))

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册