前言:appium必须是1.6以上的版本

环境(安装和安装都可以运行成功,我也不确定要不要这个)

1、抓到toast需要安装uiautomator2,安装npm:npm install -g cnpm --registry=https://registry.npm.taobao.org

2、 然后通过这个命令: cnpm install appium-uiautomator2-driver   安装uiautomator2的配置文件

一、先看看toast

二、代码实现:

#coding= utf-8
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
desired_caps = {
'platformName':"Android",
'deviceName':"R8V5T15930002010",
'platformVersion':"5.0.1",
'appPackage':"com.yuedan",
'appActivity':"com.yuedan.ui.Activity_Splash",
'unicodeKeyboard': True,#使用unicode编码方式发布字符串
'resetKeyboard': True , #屏蔽软键盘,
'automationName': 'uiautomator2',
'noReset':True
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
# 等主页面activity出现
time.sleep(20)
print(driver.current_activity)
driver.wait_activity(".ui.MainActivity", 20)
search_view = WebDriverWait(driver,10,0.1).until(EC.presence_of_element_located((By.ID, "com.yuedan:id/search_view")))
search_view.click()
search= WebDriverWait(driver,10,0.1).until(EC.presence_of_element_located((By.ID, "com.yuedan:id/iv_search")))
search.click()
toast_message = "请输入搜索关键字"
message ='//*[@text=\'{}\']'.format(toast_message)
# 获取toast提示框内容
toast_element = WebDriverWait(driver,5).until(lambda x:x.find_element_by_xpath(message))
print(toast_element.text)
driver.quit()

运行结果:

三、代码实现

#coding= utf-8
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
desired_caps = {
'platformName':"Android",
'deviceName':"R8V5T15930002010",
'platformVersion':"5.0.1",
'appPackage':"com.yuedan",
'appActivity':"com.yuedan.ui.Activity_Splash",
'unicodeKeyboard': True,#使用unicode编码方式发布字符串
'resetKeyboard': True , #屏蔽软键盘,
'automationName': 'uiautomator2'
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(2)
driver.find_element_by_id("com.yuedan:id/login").click()
time.sleep(2)
driver.find_element_by_id("com.yuedan:id/btnQuickLogin").click()
driver.find_element_by_id("com.yuedan:id/et_name").send_keys("")
driver.find_element_by_id("com.yuedan:id/tv_re_sent").click()
# 定位toast元素
toast_message = "手机号码格式错误"
message ='//*[@text=\'{}\']'.format(toast_message)
# 获取toast提示框内容
toast_element = WebDriverWait(driver,5,0.1).until(lambda x:x.find_element_by_xpath(message))
print(toast_element.text)
driver.quit()

运行结果:

uiautomator2 获取APP Toast内容的更多相关文章

  1. 如何获取app配置文件内容

    App.config: <appSettings> <add key="FCPConnection" value="Data Source=192.16 ...

  2. appium获取Toast内容的方法

    做自动化测试的时候,可能需要根据弹出的Toast提示来做下一步判断.这里记录一下获取Toast内容的方法,同时巩固一下显示等待的方法之一WebDriverWait. from selenium.web ...

  3. python 全栈开发,Day127(app端内容播放,web端的玩具,app通过websocket远程遥控玩具播放内容,玩具管理页面)

    昨日内容回顾 1. 小爬爬 内容采集 XMLY 的 儿童频道 requests 2. 登陆 注册 自动登陆 退出 mui.post("请求地址",{数据},function(){} ...

  4. app端内容播放,web端的玩具,app通过websocket远程遥控玩具播放内容,玩具管理页面

    一.app端内容播放 下载代码 https://github.com/987334176/Intelligent_toy/archive/v1.0.zip 注意:由于涉及到版权问题,此附件没有图片和音 ...

  5. Android中实现APP文本内容的分享发送与接收方法简述

    谨记(指定选择器Intent.createChooser()) 开始今天的内容前,先闲聊一下: (1)突然有一天头脑风暴,对很多问题有了新的看法和见解,迫不及待的想要分享给大家,文档已经写好了,我需要 ...

  6. iOS开发之集成iOS9中的Core Spotlight Framework搜索App的内容

    Spotlight在iOS9上做了一些新的改进, 也就是开放了一些新的API, 通过Core Spotlight Framework你可以在你的app中集成Spotlight.集成Spotlight的 ...

  7. koa1.x获取原始body内容

    Node版本比较老,koa1.x配合koa-body-parser,默认koa-body-parser会把请求数据转成json对象, 然而有的时候需要获取原始的内容,不要转换,看波koa-body-p ...

  8. robotframework + appium 获取android toast

    android toast 获取主要方式是在出现toast的时候查找元素:xpath=//*[contains(@text,'记同步')]  ,该xpath 表示为toast信息含有  "记 ...

  9. python开发_tkinter_获取文本框内容_给文本框添加键盘输入事件

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

随机推荐

  1. 模拟curl函数

    只要需要调用微信的网址,就需要模拟curl请求 $tokenUrl="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_cr ...

  2. 4.1.3 Euclid's Game (POJ 2348)

    Problem description: 以辗转相除法为基础,给定两个整数a和b,Stan和Ollie轮流从较大的数字中减去较小数字的倍数(整倍数),并且相减后的结果不能为零.Stan先手,在自己的回 ...

  3. Oracle PL/SQL游标

    游标的提出: SQL是面向集合的,其结果一般是集合量(多条记录),而PL/SQL的变量一本是标量,其一组变量异常一直只能存放一条记录.所以仅仅使用变量并不能完全满足SQL语句向应用程序输出数据的要求. ...

  4. 详解Oracle数据字典

    Oracle通过数据字典来管理和展现数据库信息,数据字典通常储存数据库的元数据,是数据库的“数据库”.通常说的数据字典由4部分组成:内部RDBMS(X$)表.数据字典表.动态性能视图(V$)和(静态) ...

  5. 用vue构建多页面应用

    最近一直在研究使用vue做出来一些东西,但都是SPA的单页面应用,但实际工作中,单页面并不一定符合业务需求,所以这篇我就来说说怎么开发多页面的Vue应用,以及在这个过程会遇到的问题. 准备工作 在本地 ...

  6. Utils--字符串的帮助类

    Utils--字符串的帮助类 一个关于字符串过滤的工具类,主要时针对username和password的过滤 package com.bw.yun.utils; import java.securit ...

  7. Mysql for Linux安装配置之—— 源码安装

    1.安装 --假设已经有mysql-5.5.10.tar.gz以及cmake-2.8.4.tar.gz两个源码压缩文件1)先安装cmake(mysql5.5以后是通过cmake来编译的)   # ta ...

  8. java中一对多 关联建表

    我们以银行卡为例:一个人可以对应多张银行卡.多个银行卡对应着一个人. /** 银行卡持有者 **/ class CardsOwner { private String name;    //名字 pr ...

  9. Ubuntu安装openssh-server并通过xshell连接

    #安装ssh sudo apt-get install openssh-server openssh-client sudo apt-get update sudo apt-get upgrade 查 ...

  10. learning at commad AT+CPSI

    [Purpose] Learning how to get mobile network info [Eevironment] Shell terminal, base on gcom command ...