Python+Appium 获取 toast 方法的封装

获取toast内容方法封装如下:

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

原文地址:https://www.cnblogs.com/syw20170419/p/8280115.html

时间: 2024-08-30 14:55:34

Python+Appium 获取 toast 方法的封装的相关文章

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 截图如下,查找如下截

python appium 封装获取toast方法

获取toast text封装,传入toast 部分文本,返回全部文本 def get_toast_text(self,text): try: toast_loc = (By.XPATH, "//*[contains(@text,'"+text+"')]") logger.info(toast_loc) ele = WebDriverWait(self.driver, 10, 0.1).until(EC.presence_of_element_located(toas

python 怎样获取toast?

toast是什么? 想要获取toast的小伙伴们,肯定知道这个是一个什么玩意,例行还是加一个图,加以解释,下图的就是传说中的toast,它有一个特点,出现时间特别短,很难通过定位元素去获取这个toast. 不能通过明确的元素定位来获取,那要怎么获取到toast呢?在做app自动化的时候,toast出现率非常高,所以必须要获取到toast,方便后面的断言.那要怎么通过什么方式获取呢? 答案就是:采用Xpath + text 进行定位 python -appium -真机 是怎样工作的? 知道通过什

Appium获取toast消息遇到的问题(一)

一.运行错误 Android获取toast,需要在参数里设置automationName:Uiautomator2 1 # 设置设备的信息 2 desired_caps = { 3 'platformName': 'Android', # 平台 4 'platformVersion': '5.1', # 版本号 5 'deviceName': 6 'appPackage': 7 'appActivity': 8 'unicodeKeyboard': 'True', # 防止键盘中文不能输入 9

Appium获取toast消息

Android获取toast,需要在参数里设置automationName:Uiautomator2 设置设备的信息 desired_caps = { 'platformName': 'Android', # 平台 'platformVersion': '5.1', # 版本号 'deviceName': 'appPackage': 'appActivity': 'unicodeKeyboard': 'True', # 防止键盘中文不能输入 'resetKeyboard': 'True', #

python+appium获取app元素属性值

元素的属性我们经常会用到,当定位到某个元素后,有时会需要用到这个元素的text值.className.resource-id.checked等. 一般标准的属性我们都可以通过get_attribute("属性名称")来获取,我们来看看下面截图的元素都是怎么获取的吧.从上到下来看.我们从text开始讲,我们先通过xpath方式定位到这个元素 获取text方法有:虽然有两种方法,但一般都用第一种,因为写法比较简单.知道有第二种方法就好了.获取resource-id值方法: 获取classn

Python + Appium 获取当前屏幕的截图方法的封装

使用方法:get_screenshot_as_file(filename),来自于selenium\webdriver\remote\webdiver.py def take_screenShot(self,name = "takeShot"): ''' method explain:获取当前屏幕的截图 parameter explain:[name] 截图的名称 Usage: device.take_screenShot(u"个人主页") #实际截图保存的结果为:

Appium获取toast消息(二)

刚接触appium进行移动端设备的UI自动化,在遇到toast消息的时候很是苦恼了一阵,最后通过强大的搜索引擎找到了个相对解决方法,废话不多说,直接贴代码↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓: 1 from selenium.webdriver.support.ui import WebDriverWait 2 from selenium.webdriver.support import expected_conditions as EC 3 4 def is_toast_exi

Python:random获取随机数用法小记

在Python中,获取随机数的方法大致有如下这些: # -*- coding:utf-8 -*- # 指定编码,否则以下中文注释运行通不过 import random # 导入random # python中利用random获取一个0到1的随机浮点数 a = random.random() print a # <span style="font-family: Arial, Helvetica, sans-serif;">python中利用random获取一定范围内的(10