python+Appium自动化:toast定位
Toast简介
Toast是一种简易的消息提示框。
当视图显示给用户,在应用程序中显示为浮动。和Dialog不一样的是,它永远不会获得焦点,无法被点击。
用户将可能是在中间键入别的东西。Toast类的思想就是尽可能不引人注意,同时还向用户显示信息,希望他们看到。
而且Toast显示的时间有限,Toast会根据用户设置的显示时间后自动消失。
举个例子:下方图片就是淘宝退出app时出现的toast信息

如果用 UI Automation Viewer这个工具是无法定位到的,那么如何进行定位呢?
这个主要是基于UiAutomator2,因此需要在Capablity配置如下参数:
'automationName': 'uiautomator2'
安装appium-uiautomator2-driver:
cnpm install appium-uiautomator2-driver
安装成功后可以在 C:\Users\XX路径\node_modules看到对应的文件:
_appium-uiautomator2-driver@1.23.0@appium-uiautomator2-driver
_appium-uiautomator2-server@2.6.0@appium-uiautomator2-server
具体代码如下:
from appium import webdriver
from selenium.common.exceptions import NoSuchElementException
import time
from selenium.webdriver.support.ui import WebDriverWait
desired_caps = {
"platformName": "Android",
"platformVersion": "5.1",
"deviceName": "U4KF9HSK99999999",
"appPackage": "com.taobao.taobao",
"appActivity": "com.taobao.tao.welcome.Welcome",
"unicodeKeyboard":True,
"resetKeyboard":True,
"noReset": True,
"automationName": "Uiautomator2"
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(1)
driver.back()
# 用xpath定位
toast_message = "再按一次返回键退出手机淘宝"
message ='//*[@text=\'{}\']'.format(toast_message)
#显示等待检测元素
toast_element=WebDriverWait(driver, 5).until(lambda x:x.find_element_by_xpath(message))
print(toast_element.text)
#结果进行比较
assert toast_element.text == "再按一次返回键退出手机淘宝"
python+Appium自动化:toast定位的更多相关文章
- python+Appium自动化:id元素定位
元素定位 与web自动化一样,app自动化元素定位也是非常重要的一环,,appium也是提供了很多元素定位的方法,比如:id.name.class.层级定位等等. 元素定位方式 id name cla ...
- python+Appium自动化:H5元素定位
问题思考 在混合开发的App中,经常会有内嵌的H5页面.那么这些H5页面元素该如何进行定位操作呢? 解决思路 针对这种场景直接使用前面所讲的方法来进行定位是行不通的,因为前面的都是基于Andriod原 ...
- python+appium 自动化2--元素定位uiautomatorviewer
出处:https://www.cnblogs.com/yoyoketang/p/6128741.html 前言: 可以打开手机上的app了,下一步元素定位uiautomatorviewer,通过定位到 ...
- python+Appium自动化:各种元素定位方法
name定位 driver.find_element_by_name('飞利浦净水').click() 测试结果报错:selenium.common.exceptions.InvalidSelecto ...
- python appium使用uiselector定位时,提示 Could not parse UiSelector argument: 'XXX' is not a string
运行自动化代码,appium返回Could not parse UiSelector argument: 'XXX' is not a string,其中的xxx就是定位的元素 解决方案:外侧用 '' ...
- Python+Appium自动化环境搭建
appium工作原理 appium 在android端工作流 client端也就是我们 test script是我们的webdriver测试脚本. 中间是起的Appium的服务,Appium在服务端起 ...
- python+Appium自动化:读取Yaml配置文件
Yaml简介 Yaml:"Yet Another Markup Language"(是一种标记语言),但为了强调这种语言以数据做为中心,而不是以标记语言为重点,而用反向缩略语重命名 ...
- Python + Appium 自动化操作微信入门看这一篇就够了
简介 Appium 是一个开源的自动化测试工具,支持 Android.iOS 平台上的原生应用,支持 Java.Python.PHP 等多种语言. Appium 封装了 Selenium,能够为用户提 ...
- python appium自动化报“Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server
运行app自动化代码时报"Encountered internal error running command: UnknownError: An unknown server-side e ...
随机推荐
- Python学习笔记——类和对象
类和对象 1. 一个例子 # 对象 = 属性 + 方法 # Python 中的类名称约定首字母大写,而 Python 函数名首字母小写 class Turtle: #属性 color = 'green ...
- Django soft-delete软删除
在django中,实现这个功能很简单,我们采用一个字段用来保存删除的时间.若记录没有被删除,那么设置该值为None,如果被删除,那么设置时间为删除的时间. class BaseSchema(model ...
- [转帖]phoronix-test-suite测试云服务器
phoronix-test-suite测试云服务器 https://www.cnblogs.com/tanyongli/p/7767804.html centos系统 phoronix-test-su ...
- Elasticsearch使用小结之冷热分离
Elasticsearch使用小结之冷热分离 索引迁移 索引setting中的index.routing.allocation.exclude和index.routing.allocation.inc ...
- linux中学习中提炼出来的命令
Linux: 基于debain的系统(如:Ubuntu等)pms基本工具:aptitude[apt-get],dpkgaptitude search package_name 查看软件包是否已安装,如 ...
- linux命令(ubuntu18)记录...
1.解压.zip文件unzip unzip studentCRUD-master.zip 2.读写权限chmod指令 r表是读 (Read) .w表示写 (Write) .x ...
- k8s-helm安装
kubernetes 1.15安装部署helm插件 简单介绍: Helm其实就是一个基于Kubernetes的程序包(资源包)管理器,它将一个应用的相关资源组织成为Charts,并通过Charts ...
- 怎样设置cookie的到期时间
1. 使用Cookie的: Expires 属性. 它可以设置cookie的过期时间. 下面的代码表示id这条cookie的过期时间是2015年10月21日早上7点28分; Set-Cookie: i ...
- 高性能网站建设之 MS Sql Server数据库分区
什么是数据库分区?数据库分区是一种对表的横向分割,Sql server 2005企业版和之后的Sql server版本才提供这种技术,这种对表的横向分割不同于2000中的表分割,它对访问用户是透明的, ...
- RestShrap Simple REST and HTTP Client for .NET 了解
最近做一个项目,需要上传文件到文件服务器, 文件服务器是 内部的webapi形式的接口.经朋友推荐使用restshrap , 例子: //上传文件 var request=new RestClient ...