Python+Appium 查找 toast 方法的封装

使用场景:在操作应用时常见toast弹框,通过toast弹框信息的获取判断当前的某个操作是否成功

引用的包:from selenium.webdriver.support import expected_conditions as EC,\expected_conditions

      from selenium.webdriver.common.by import By
      from selenium.webdriver.support.ui import WebDriverWait

截图如下,查找如下截图中的toast内容,判断给出的值是否与实际toast的值是否相等,相等则正常执行,不相等直接走except异常内容,如下:

  

 

第一种封装方法:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC,\
    expected_conditions

def find_Toast2(self,message): #查找toast值
''' method explain:查找toast的值,与find_Toast实现方法一样,只是不同的2种写法 parameter explain:【text】查找的toast值 Usage: device.find_Toast2('再按一次退出iBer') ''' logging.info("查找toast值---'%s'" %(message)) try: message = '//*[@text=\'{}\']'.format(message) WebDriverWait(self.driver,5,0.5).until(expected_conditions.presence_of_element_located((By.XPATH,message))) logging.info("查找到toast----%s"%message) return True except: logging.info("未查找到toast----%s"%message) return False

 

第二种封装方法如下:

def find_Toast(self,message,timeout=5,poll_frequency = 0.5):  #查找toast值
        '''
        method explain:查找toast的值
        parameter explain:【text】给定的toast值
        Usage:
            device.find_Toast('再按一次退出iBer')
        '''
        logging.info("获取toast值---'%s'" %message)
        try:
            toast_loc = ("xpath",".//*[contains(@text,'%s')]" %message)
            WebDriverWait(self.driver,timeout,poll_frequency).until(EC.presence_of_element_located(toast_loc))
            logging.info("查找到toast--'%s'"%message)
            return True
        except:
            logging.info("未查找到toast--'%s'"%message)
            return False

 说明:

  获取toast的方法封装点击链接:http://www.cnblogs.com/syw20170419/p/8280115.html

转载于:https://www.cnblogs.com/syw20170419/p/8280100.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值