您的位置:首页 > 移动开发

python对app页面元素进行封装并设置查找时间操作实例

2017-03-27 18:48 851 查看
#coding=utf8
'''
获取顶部元素:
推荐、热门、分类、榜单、主播
'''
from publicLib.findElement import appDriver
from selenium.webdriver.support.ui import WebDriverWait
from publicLib.appInit import appInit

class topBar(object):
def __init__(self,appdriver):
try:
self.driver=appdriver
except Exception,e:
print "Top Bar ",e

def recommandEle(self,timeout=10):
try:
'''一直查找元素:推荐,默认10秒超时'''
recommandEle=WebDriverWait(self.driver,timeout).until(lambda driver:driver.app_find_element_by_text("推荐"),"Can not find recommand element")
return recommandEle
except Exception,e:
print "Find recommane element  ",e

def hotdoorEle(self,timeout=10):
try:
'''一直查找元素:热门,默认10秒超时'''
hotdoorEle=WebDriverWait(self.driver,timeout).until(lambda driver:driver.app_find_element_by_text("热门"),"Can not find hotdoor element")
return hotdoorEle
except Exception,e:
print "Find hotdoor element  ",e

def classificationEle(self,timeout=10):
try:
'''一直查找元素:分类,默认10秒超时'''
classificationEle=WebDriverWait(self.driver,timeout).until(lambda driver:driver.app_find_element_by_text("分类"),"Can not find classification element")
return classificationEle
except Exception,e:
print "Find classification element  ",e

def  billboardEle(self,timeout=10):
try:
'''一直查找元素:榜单,默认10秒超时'''
billboardEle=WebDriverWait(self.driver,timeout).until(lambda driver:driver.app_find_element_by_text("榜单"),"Can not find  billboard element")
return billboardEle
except Exception,e:
print "Find billboard element  ",e

def  anchorEle(self,timeout=10):
try:
'''一直查找元素:主播,默认10秒超时'''
billboardEle=WebDriverWait(self.driver,timeout).until(lambda driver:driver.app_find_element_by_text("榜单"),"Can not find  anchor element")
return billboardEle
except Exception,e:
print "Find anchor element  ",e

def test():
appdriver=appDriver()
appInit(appdriver)
recommand=topBar(appdriver)
recommand.recommandEle().click()
appdriver.quitApp()

if __name__=="__main__":
test()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐