前言: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. 2.2 UML用例模型

    参与者(Actor) 参与者(注:有另一种翻译“执行者”) 代表位于系统之外并和系统进行交互的一类事物(人.物.其他软件子系统等) 通过它,可以对软件系统与外界发生的交互进行分析和描述 通过它,可以了 ...

  2. nginx本地缓存

    Nginx 作为Web服务器或者负载均衡器,一般不执行业务逻辑,而是将请求转到后端服务器,比如 Tomcat 或者 php-fpm,后端处理完毕之后将经过 nginx 将数据返回给用户.在请求转发的过 ...

  3. python-flask-wtforms

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. PAT 1011 World Cup Betting

    1011 World Cup Betting (20 分)   With the 2010 FIFA World Cup running, football fans the world over w ...

  5. 通过cassandra-cli客户端了解cassandra的内部数据结构

    和cassandra数据库交互的方式有两种,一种是通过类似于cassandra-cli命令的thrift api,或者通过cassandra提供的cql(cassandra query lanugag ...

  6. ajax实现给JavaScript中全局变量赋值(转)

    原文地址:ajax实现给JavaScript中全局变量赋值 问题简化: <script type="text/javascript"> var a=1 ; functi ...

  7. Android Studio build gradle project info 卡主不动解决方法.

    项目里的: build.gradle 依赖 的gradle 版本 在每个项目里 gradle/wrapper/properties/gradle-wrapper.properties 配置文件里 用户 ...

  8. springboot aop 自定义注解方式实现一套完善的日志记录(完整源码)

    https://www.cnblogs.com/wenjunwei/p/9639909.html https://blog.csdn.net/tyrant_800/article/details/78 ...

  9. Mysql 用户ip访问根据省份查询

    表名:shop_interview_customer 表结构:customerId空为游客模式 interviedId customerId interviewIP iPdetail 1 1001 1 ...

  10. Mac下安装和配置Maven

    1.下载Maven 官网:http://maven.apache.org/download.cgi 下载版本:apache-maven-3.5.3-bin.tar.gz 2.配置环境变量 打开term ...