appium+python自动化37-adb shell模拟点击事件(input tap)

前言

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 device


C:\Users\Gloria>adb shell
root@android:/ # input
Usage: input [<source>] <command> [<arg>...]

The sources are:
      trackball
      joystick
      touchnavigation
      mouse
      keyboard
      gamepad
      touchpad
      dpad
      stylus
      touchscreen

The 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脚本,也能达到同样效果

猜你喜欢

转载自www.cnblogs.com/yoyoketang/p/8983193.html
今日推荐