前言: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. 使用VisualStudio进行脚本|样式文件压缩

    在vs的Optimization中有个Bundle是专门用来压缩样式和脚本文件 .他有两个继承:StyleBundle.ScriptBundle,从名字上就可看出,StyleBundle专门压缩样式文 ...

  2. SE-Net要点

    关于SE-Net有些很奇妙的点: 1.首先,所谓的SE module加在了BN层后面,这样的话,SE首先应该是对于BN层输出的feature map求取global average pooling,一 ...

  3. A Chess Game POJ - 2425

    Let's design a new chess game. There are N positions to hold M chesses in this game. Multiple chesse ...

  4. 【洛谷p1164】小A点菜

    (……) 小A点菜[传送门] 上标签: (一个神奇的求背包问题方案总数的题) 核心算法: ;i<=n;i++) for(int j=m;j>=a[i];j--) f[j]+=f[j-a[i ...

  5. project euler113

    project euler 113 对于1个数字,如果他数位不减或者不增称为bouncy number,比如1233,33210.统计1-10^100中的bouncy number   思路:分为两种 ...

  6. leetcode-algorithms-36 Valid Sudoku

    leetcode-algorithms-36 Valid Sudoku Determine if a 9x9 Sudoku board is valid. Only the filled cells ...

  7. Leetcode 1006. 笨阶乘

    1006. 笨阶乘  显示英文描述 我的提交返回竞赛   用户通过次数305 用户尝试次数347 通过次数309 提交次数665 题目难度Medium 通常,正整数 n 的阶乘是所有小于或等于 n 的 ...

  8. SQL SERVER版本补丁体系及升级

    首先了解几个定义: RTM : 表示 Release to Manufacturing ,这是产品的原始发布版本,当从光盘或 MSDN 下载的默认版本.不过现在下载 SQL Server 版本时,也有 ...

  9. 梯度下降法的三种形式BGD、SGD以及MBGD

    https://www.cnblogs.com/maybe2030/p/5089753.html 阅读目录 1. 批量梯度下降法BGD 2. 随机梯度下降法SGD 3. 小批量梯度下降法MBGD 4. ...

  10. Oracle.练习题

    2018-07-31 ---练习3 ---创建sporter表 create table sporter( sporterid ) constraint sport_id primary key, s ...