最好的学习方法,就是看源码!

在  \appium\webdriver\webdriver.py ,新增了两个封装好定位安卓元素的方法,如  find_element_by_accessibility_id 与 find_element_by_android_uiautomator

如下图,定位“一起玩”tab页:

一、根据UIAutomator定位元素

    def test_find_element(self):
self.driver.wait_activity('com.yy.mobile.ui.home.MainActivity',30)
# text 属性的方法
el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("一起玩")')
self.assertIsNotNone(el)
e2 = self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("起玩")')
self.assertIsNotNone(e2)
e3 = self.driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("一起")')
self.assertIsNotNone(e3)
e4 = self.driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^一起.*")')
self.assertIsNotNone(e4)
# class属性的方法
e5 = self.driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.TextView").text("一起玩")')
self.assertIsNotNone(e5)
# resourceId属性的方法
e6 = self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.yy.mobile.plugin.main:id/tab_tab_btn")')
self.assertIsNotNone(e6)

二、根据accessibility_id定位

    def find_element_by_accessibility_id(self, id):
"""Finds an element by accessibility id. :Args:
- id - a string corresponding to a recursive element search using the
Id/Name that the native Accessibility options utilize :Usage:
driver.find_element_by_accessibility_id()
"""
return self.find_element(by=By.ACCESSIBILITY_ID, value=id)

对于 Android 就是 content-description

对于 iOS 就是 accessibility identifier

三、看源码可知,Appium 中的Webdriver是Selenium中的webdirver.Remote的子类,所以更多的API,可是在Selenium中寻找

***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***

Appium 自动化测试(8) -- Appium Python client -- API的更多相关文章

  1. Python+Appium自动化测试(1)-appium环境搭建

    用python+appium做appUI自动化测试,系统为Windows.首先是JDK与Android SDK的安装与环境变量的设置. 一,安装JDK,配置JDK环境变量 1,下载jdk jdk8官网 ...

  2. Python+Appium自动化测试(2)-appium连接真机启动app

    app自动化测试的第一步,是启动被测app.appium环境搭建好后,我们就可以连接真机启动app了.环境为windows,Appium1.18.0,Android手机,被测app为今日头条app,让 ...

  3. Python+Appium自动化测试(5)-appium元素定位常用方法

    对于Android而言,查找appUI界面元素属性的工具有三种:appium desktop,uiautomatorviewer.bat,weditor.之前已经介绍过了weditor的使用,这里我将 ...

  4. appium自动化测试框架——在python脚本中执行dos命令

    一般我们运行dos命令,会有两种需求,一种是需要收集执行结果,如ip.device等:一种是不需要收集结果,如杀死或开启某个服务. 对应的在python中就要封装两种方法,来分别实现这两种需求. 1. ...

  5. Appium自动化测试教程-自学网-monkeyrunner API

    MonkeyRunner API MonkeyRunner工具主要有三个类: MonkeyRunner MonkeyDevice MonkeyImage 官方API文档 :http://www.and ...

  6. Appium 自动化测试(3)--Appium框架与流程介绍

    Appium介绍 Appium是一个移动端的自动化框架,可用于测试原生应用,移动网页应用和混合型应用,且是跨平台的.可用于IOS和Android以及firefox的操作系统.原生的应用是指用andro ...

  7. Appium 自动化测试(7) -- Appium 服务器初始化参数设置

    Desired Capabilities Desired capabilities 是一些发送给 Appium 服务器的键值对集合 (比如 map 或 hash),告诉服务器我们想要启动什么类型的自动 ...

  8. Python Client API文档

    官网文档地址:http://docs.minio.org.cn/docs/master/python-client-api-reference 初使化MinIO Client对象 from minio ...

  9. Appium 自动化测试(5)-- Appium详细介绍:Appium 手机自动化测试_TesterHome公开版pdf

随机推荐

  1. Spring 体系结构

    https://www.w3cschool.cn/wkspring/dcu91icn.html 体系结构 Spring 有可能成为所有企业应用程序的一站式服务点,然而,Spring 是模块化的,允许你 ...

  2. Django - CBV、FBV

    一.FBV FBV(function base views) 就是在视图里使用函数处理请求. 在之前django的学习中,我们一直使用的是这种方式. 二.CBV CBV(class base view ...

  3. 002-Spring Framework-Core-01-IoC容器

    一.概述 文章地址:https://docs.spring.io/spring/docs/5.0.6.RELEASE/spring-framework-reference/ 核心主要包括:IoC co ...

  4. 一个简单的3D范例,是在别人基础上面整理的。

    一个简单的范例,是在别人基础上面整理的.原来的例子,框图太乱了,没有条理感. http://pan.baidu.com/s/1eQTyGCE

  5. SimpleDateFormat实现String与Date之间的转换

    基本用法: java.text.SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd"); java.util.Date ...

  6. 时间格式—My97DatePicker控件使用

    一.My97DatePicker控件使用(2步):   1:JSP页面:( class="Wdate" 显示控件图标) 引入控件包中的脚本: <script type=&qu ...

  7. Codeforces Round #520 (Div. 2) Solution

    A. A Prank Solved. 题意: 给出一串数字,每个数字的范围是$[1, 1000]$,并且这个序列是递增的,求最多擦除掉多少个数字,使得别人一看就知道缺的数字是什么. 思路: 显然,如果 ...

  8. 466E - Information Graph 巧妙的判断祖先于孩子的关系

    这题说的是给了一个公司员工100000 然后现在又3种操作第一种将y置为x的父亲,第二种操作将文件给第x个人签他签完给他的上司签,一直到没有上司为止,第三种操作问x是否签了第i份文件,然后 我们只要直 ...

  9. flask应用中取得config的配置

    from flask import current_app config = current_app.config SITE_DOMAIN = config.get('SITE_DOMAIN')

  10. SQL case when 多条件查询

    基于列的逻辑表达式,其实就是CASE表达式.可以用在SELECT,UPDATE,DELETE,SET以及IN,WHERE,ORDER BY和HAVING子句之后.下面给个简单示例: