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腳本,也能達到同樣效果


在學習過程中有遇到疑問的,可以appium+python QQ群交流:330467341


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM