首页 技术 正文
技术 2022年11月10日
0 收藏 820 点赞 3,988 浏览 1205 个字

前言

appium有时候定位一个元素很难定位到,或者说明明定位到这个元素了,却无法点击,这个时候该怎么办呢?

求助大神是没用的,点击不了就是点击不了,appium不是万能的,这个时候应该转换思路,换其它的方法去点击,比如我们可以用adb去执行点击事件

input事件

1.先查看input事件语法有哪些,首先确保手机连上电脑(我这里是电脑上打开的手机模拟器)

> adb device
> adb shell
> input
C:\Users\Gloria>adb devices
List of devices attached
127.0.0.1:52007 deviceC:\Users\Gloria>adb shell
root@android:/ # input
Usage: input [<source>] <command> [<arg>...]The sources are:
trackball
joystick
touchnavigation
mouse
keyboard
gamepad
touchpad
dpad
stylus
touchscreenThe commands and default sources are:
text <string> (Default: touchscreen)
keyevent [--longpress] <key code number or name> ... (Default: keyboard)
tap <x> <y> (Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)
root@android:/ #

2.input可以实现的功能

  • 输入文本信息:input text yoyo

  • 物理按键操作: input keyevent KEYCODE_VOLUME_DOWN

  • 点击(DOWN_UP)操作:input tap 500 500

  • 模拟滑动操作:input swipe 200 500 400 500

  • 模拟轨迹球操作 input roll 100 200

input tap

1.input tap实现的是DOWN_UP事件,也就是点击操作,后面两个参数是点击的坐标x,y

2.举个例子:点击淘宝app的icon图标,先查看坐标[149,388][290,618],大概可以算出需要点击的点为(200, 500)

打开cmd,输入adb执行,这个时候可以看到淘宝app已经启动了

> adb shell input tap 200 500

3.再继续点击淘宝上的‘我的淘宝’按钮 (600, 1250)

> adb shell input tap 600 1250

python执行adb命令

1.回到手机的home首页,执行以下python脚本,也能达到同样效果

在学习过程中有遇到疑问的,可以appium+python QQ群交流:330467341

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290