Appium识别toast

1.appium识别toast对appium版本有要求,必须使用1.6.3以上才能识别toast

2.识别toast需要使用Uiautomator2库,所以需要安装Uiautomator2

3.需要在Capablity配置如下参数:
desired_caps['automationName']='uiautomator2'

4.Toast内容为中文时,顶部必须注释# coding=utf-8 否则会因为编解码导致文字识别失败。

代码如下

from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from appium import webdriver
from selenium.webdriver.support import expected_conditions as EC


desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '5.1.1'
        desired_caps['deviceName'] = 'Android Emulator'
        desired_caps['appPackage'] = 'com.topsec.topsap'
        desired_caps['appActivity'] = 'com.topsec.topsap.main.Welcome'
        # 'automationName':'Selendroid'
        desired_caps['automationName'] = 'Uiautomator2'
        desired_caps['noReset']="True"
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    def is_toast_exist(self, message):
        try:
            element = WebDriverWait(self.driver, 10, 0.01).until(
                EC.presence_of_all_elements_located((By.XPATH, '//*[@text=\'{}\']'.format(message))))
            for i in element:
                print i.text
            return True
        except Exception, e:
            log.error(e.message)
            return False

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值