uiautomator2 获取APP Toast内容
前言: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内容的更多相关文章
- 如何获取app配置文件内容
App.config: <appSettings> <add key="FCPConnection" value="Data Source=192.16 ...
- appium获取Toast内容的方法
做自动化测试的时候,可能需要根据弹出的Toast提示来做下一步判断.这里记录一下获取Toast内容的方法,同时巩固一下显示等待的方法之一WebDriverWait. from selenium.web ...
- python 全栈开发,Day127(app端内容播放,web端的玩具,app通过websocket远程遥控玩具播放内容,玩具管理页面)
昨日内容回顾 1. 小爬爬 内容采集 XMLY 的 儿童频道 requests 2. 登陆 注册 自动登陆 退出 mui.post("请求地址",{数据},function(){} ...
- app端内容播放,web端的玩具,app通过websocket远程遥控玩具播放内容,玩具管理页面
一.app端内容播放 下载代码 https://github.com/987334176/Intelligent_toy/archive/v1.0.zip 注意:由于涉及到版权问题,此附件没有图片和音 ...
- Android中实现APP文本内容的分享发送与接收方法简述
谨记(指定选择器Intent.createChooser()) 开始今天的内容前,先闲聊一下: (1)突然有一天头脑风暴,对很多问题有了新的看法和见解,迫不及待的想要分享给大家,文档已经写好了,我需要 ...
- iOS开发之集成iOS9中的Core Spotlight Framework搜索App的内容
Spotlight在iOS9上做了一些新的改进, 也就是开放了一些新的API, 通过Core Spotlight Framework你可以在你的app中集成Spotlight.集成Spotlight的 ...
- koa1.x获取原始body内容
Node版本比较老,koa1.x配合koa-body-parser,默认koa-body-parser会把请求数据转成json对象, 然而有的时候需要获取原始的内容,不要转换,看波koa-body-p ...
- robotframework + appium 获取android toast
android toast 获取主要方式是在出现toast的时候查找元素:xpath=//*[contains(@text,'记同步')] ,该xpath 表示为toast信息含有 "记 ...
- python开发_tkinter_获取文本框内容_给文本框添加键盘输入事件
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
随机推荐
- yii框架中使用gii的用法
首先在config文件中的 main-local.php中添加一句 'allowedIPs' => ['*'],如下图所示:
- 串的模式匹配算法 ------ KMP算法
//KMP串的模式匹配算法 #include <stdio.h> #include <stdlib.h> #include <string.h> int* get_ ...
- array_column的作用
从记录集中取出 last_name 列,用相应的 "id" 列作为键值: <?php // 表示由数据库返回的可能记录集的数组 $a = array( array( 'id' ...
- Spring中添加新的配置表,并对新的配置表进行处理
实习过程中boss交代的任务(以下出现的代码以及数据只给出小部分,提供一个思路) 目的:Spring中添加新的配置表,并对新的配置表进行处理:替换的新的配置表要友好,同时保证替换前后功能不能发生变化. ...
- Python PIL模块笔记
利用python pil 实现给图片上添加文字 图片中添加文字#-*- coding: utf-8 -*- from PIL import Image,ImageDraw,ImageFont ttfo ...
- Activiti搭建
Activiti搭建 前期准备: JDK+Eclipse+Tomcat+Maven的安装与配置 参考:http://blog.csdn.net/zhshulin/article/details/307 ...
- c++ shared_ptr的使用
shared_ptr.是c++为了提高指针安全性而添加的智能指针,方便了内存管理.功能非常强大,非常强大,非常强大(不单单是shared_ptr,配合week_ptr以及enable_share_fr ...
- hdu-6397-容斥
Character Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- Python----list&元祖常用方法总结
一.创建列表,把使用逗号分隔的数据用中括号[ ]括起来即为一个列表,列表也叫数组.list.array:列表里面也可以再套列表,一个列表里面套一个列表,叫二维数组:一个里面套一个列表,里面的列表再套 ...
- WebView中JS调用Android Method 遇到的坑整理
WebView是android中常用的一个组件,其作用是展示网页,并让网页和android app进行一些业务逻辑上的交互. 其坑无数,相信用过的都知道,一个一个来解决吧. 1.怎么互调: <! ...