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

原创
2017/07/21 08:53
阅读数 14
#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()

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部