appium+python automation 37-adb shell simulates click events (input tap)

foreword

Sometimes it is difficult for appium to locate an element, or it indicates that the element is located but cannot be clicked. What should I do at this time?
It’s useless to ask for help. If you can’t click, you can’t click. Appium is not omnipotent. At this time, you should change your thinking and use other methods to click. For example, we can use adb to execute click events.

input event

1. First check the input event syntax, first make sure that the phone is connected to the computer (I am here is the phone simulator opened on the computer)

> 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. Functions that can be implemented by input

  • Enter text information: input text yoyo

  • Physical key operation: input keyevent KEYCODE_VOLUME_DOWN

  • Click (DOWN_UP) operation: input tap 500 500

  • Simulate swipe operation: input swipe 200 500 400 500

  • Simulate trackball operation input roll 100 200

input tap

1. The input tap implements the DOWN_UP event, which is the click operation. The last two parameters are the coordinates x, y of the click.

2. For example: Click the icon icon of Taobao app, first check the coordinates [149,388][290,618], you can probably calculate the point to be clicked as (200, 500)

Open cmd, enter adb to execute, at this time you can see that Taobao app has been started

> adb shell input tap 200 500

3. Continue to click the 'My Taobao' button on Taobao (600, 1250)

> adb shell input tap 600 1250

python execute adb command

1. Go back to the home page of the mobile phone and execute the following python script to achieve the same effect

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325168106&siteId=291194637