Windows环境下使用uiautomatorviewer进行元素定位
一、摘要
元素定位本篇主要介绍如何使用uiautomatorviewer,通过定位到页面上的元素,然后进行相应的点击等操作,uiautomatorviewer 是 android-sdk 自带的一个元素定位工具,非常简单好用,使用 uiautomatorviewer,你可以检查一个应用的 UI 来查看应用的布局和组件以及相关的属性
在WIndows系统上进行元素定位,建议使用这个工具,在Mac上建议用Appium Inspector
二、启动uiautomatorviewer.bat

双击启动

三、链接手机
确认连接手机状态正常-》打开手机qq页面,让屏幕处于点亮状态
点左上角安卓机器人按钮 Devices Screenshot 按钮刷新页面

四、定位元素

五、点击登录按钮代码实例
如上图所示,定位了登陆按钮,代码实例如下
# python
'''
@Time : 2018/11/12 13:37
@Author :
@Email :
@File :
@Software: PyCharm
@Description:
'''
# encoding = utf-8
from appium import webdriver
import time
import unittest class test_ClickButon(unittest.TestCase):
def setUp(self):
desired_caps = {
'platformName': 'Android',
'deviceName': '30d4e606',
'platformVersion': '5.0',
'appPackage': 'com.tencent.qqpimsecure',
'appActivity': 'com.tencent.server.fore.QuickLoadActivity'
}
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) def test_ClickButton(self):
driver = self.driver
driver.find_element_by_id("com.tencent.mobileqq:id/btn_login").click()
time.sleep(5)
// Java
package testscript;/*
* @FileName testscript.Test_Calculator:
* @author davieyang
* @create 2018-11-20 11:02
*/
import org.apache.log4j.xml.DOMConfigurator;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit; import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import io.appium.java_client.android.AndroidDriver; public class Test_Calculator {
static {
//指定log4j配置文件为log4j.xml
DOMConfigurator.configure("log4j.xml");
}
AndroidDriver driver;
@BeforeTest
public void setUp() throws MalformedURLException{
DesiredCapabilities caps = new DesiredCapabilities();
// des.setCapability("app", "c:\\");
caps.setCapability("automationname", "Appium");
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "23");
caps.setCapability("udid", "WTKDU17105005171");
caps.setCapability("deviceName", "Honor");
caps.setCapability("appPackage", "com.tencent.qqpimsecure");//com.android.contacts
caps.setCapability("appActivity", "com.tencent.server.fore.QuickLoadActivity");//.activities.PeopleActivity
caps.setCapability("appWaitActivity", "com.tencent.server.fore.QuickLoadActivity");
caps.setCapability("unicodeKeyboard", "True");
caps.setCapability("resetKeyboard", "True");
caps.setCapability("newCommandTimeout", "15");
caps.setCapability("nosign", "True");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),caps);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void add() {
driver.findElement(By.xpath("com.tencent.mobileqq:id/btn_login")).click();
}
六、Finding Elements By ID

WebElement digit_5 = driver.findElement(By.id("com.android.calculator2:id/digit5"));
七、Finding Elements By Name

WebElement delete = driver.findElement(By.name("DELETE"));
八、Finding Elements By CLASSNAME

WebElement editBox = driver.findElement(By.className("android.widget.EditText"));
If the same class is used for multiple elements, then we need to select an element on the basic of indexing. For example:
List<WebElement>editBox = driver.findElements(By.className("android.widget.Button"));
editBox.get(1).click();
九、Finding Elements By AccessibilityID

WebElement plusSign=driver.findElementByAccessibilityId("plus");
十、Finding Elements By AndroidUIAutomator
findElement(By.AndroidUIAutomator(String UIAuto));
WebElement equal = driver.findElementByAndroidUiAutomator("new UiSelector().resourceId(\"com.android.calculator2:id/equal\")")
WebElement equal = driver.findElementByAndroidUiAutomator("new UiSelector().description(\"equals\")");
十一、其他定位方式

Windows环境下使用uiautomatorviewer进行元素定位的更多相关文章
- Windows环境下的MYSQL5.7配置文件定位
1.MYSQL安装目录 select @@basedir; 2.MYSQL数据文件目录 select @@datadir; 3.相应地,配置文件在数据文件上一级目录中 4.停止MYSQL服务 net ...
- Windows环境下MongoDB的安装与配置
MongoDB是一种高性能的文档型数据库,现介绍一下在Windows环境下MongDB的安装与配置 获取MongoDB 打开官方网站 www.mongodb.org,找到页面右上解的DownLoad链 ...
- 第一部分:使用iReport制作报表的详细过程(Windows环境下)
提示:在有些板块,文中的图片看不到,建议到我的blog浏览文章:http://blog.csdn.net/jemlee2002/文章将会涉及3个方面的内容: 第一部分:使用iReport制作报表的详细 ...
- Windows环境下32位汇编语言程序设计(典藏版)
Windows环境下32位汇编语言程序设计(典藏版)(含CD光盘1张)(年,经典再现!) 罗云彬 著 ISBN 978-7-121-20759-4 2013年7月出版 定价:99.00元 756页 1 ...
- windows环境下搭建ffmpeg开发环境
ffmpeg是一个开源.跨平台的程序库,能够使用在windows.linux等平台下,本文将简单解说windows环境下ffmpeg开发环境搭建过程,本人使用的操作系统为windows ...
- 浅谈Windows环境下DOS及MS-DOS以及常见一些命令的介绍
浅谈Windows环境下DOS及MS-DOS以及常见一些命令的介绍 前记 自己是搞编程的,首先我是一个菜鸟,接触计算机这么久了,感觉很多计算机方面的技术和知识朦朦胧胧.模模糊糊,貌似有些贻笑大方了:所 ...
- windows环境下永久修改pip镜像源的方法(转)
一.在windows环境下修改pip镜像源的方法(以python3.7为例) (1):在windows文件管理器中,输入 %APPDATA%,cmd里面输入即可. (2):会定位到一个新的目录下,在该 ...
- 一、在windows环境下修改pip镜像源的方法(以python3为例)
在windows环境下修改pip镜像源的方法(以python3为例) 1.在windows文件管理器中,输入 %APPDATA% 2.会定位到一个新的目录下,在该目录下新建pip文件夹,然后到pip文 ...
- windows环境下apache-apollo服务器搭建及发布订阅测试
查证了一些资料之后,发现 apache-apollo服务器使用的人还是挺多的,资料也比较齐全,所以直接选择 apache-apollo了,具体性能如何,先用起来再说吧: 1.下载 apache-apo ...
随机推荐
- linux中高级信号函数sigaction和sigqueue实例
/************************************************************************* > File Name: sigquque. ...
- Spring 控制器重定向
1.示例 return "redirect:/allUser"; redirect是跳转的意思后面是跳转的页面
- spring的控制器如何获取参数
1.控制器代码 获取参数的注解 @RequestParam(name="name", required=false, defaultValue="World") ...
- JavaScript 真值和假值
常见的假值有 值 说明 var a=false; 值为假 var a =0; 值为0 var a=''; 值为空 var a=10/'abc' 算式错误 var a; 未赋值变量 常见的真值有 ...
- cpp调用c的动态库
目录 cpp调用c的动态库 title: cpp调用c的动态库 date: 2019/11/22 20:34:29 toc: true --- cpp调用c的动态库 CPP文件里这么引用头文件即可 e ...
- vue用echarts 画3d地球 且画线
页面效果如下: 项目结构如下: 引入的包 "dependencies": { "core-js": "^3.3.2", "regi ...
- PTA(Advanced Level)1050.String Subtraction
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking all the char ...
- [转帖]phoronix-test-suite 简介
<工作杂记>之phoronix-test-suite 2017年10月30日 14:32:52 打雷下雨 阅读数 2078更多 分类专栏: # linux 版权声明:本文为博主原创文章 ...
- springboot集成mongoDB简易使用
1.首先是添加Spring Data mongo的配置依赖 <dependency> <groupId>org.springframework.boot</groupId ...
- java--键盘输入任意数字进行求和
思路,我将键盘输入的数放入数组,然后便利数组进行求和 package com.test.day01; import java.util.Scanner; public class Test { pub ...