python 使用 adb 模拟滑动手机(自动观看小视频)

  1. adb模拟点击手机
    adb shell input 简单总结(转)

  2. python 使用 adb 命令

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
from time import sleep


# adb 模拟滑动手势(以步长200 从坐标350,1580 滑动到350,680)
def adb_swipe():
    os.system("adb shell input swipe 350 1580 350 680 200")
    sleep(1.0)
# adb 模拟点击动作(点击坐标356,890)
def adb_tap():
    os.system("adb shell input input tap 356 890")
    sleep(1.0)
# adb 模拟键盘事件(点击"返回")
def adb_keyevent():
    os.system("adb shell input input keyevent 4")
    sleep(1.0)


if __name__ == "__main__":
    adb_tap()
    adb_swipe()
    adb_keyevent()
  1. 安卓手机查看坐标方法
    realme X50 5G 打开USB调式步骤
    打开开发者选项, 在开发者选项中找到并打开"指针位置";
    如下图,点击"指纹\面部与密码"时, 上方的X:899.0 Y:1372.0 即是点击处的坐标
    python 使用 adb 模拟滑动手机(自动观看小视频)_第1张图片

4.自动滑动观看小视频

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
from time import sleep

# adb 模拟滑动手势(以步长200 从坐标350,1580 滑动到350,680)
def adb_swipe():
    # 滑动10次, 两次之间间隔15秒
    for i in range(10):
        os.system("adb shell input swipe 350 1580 350 680 200")
        sleep(15.0)

if __name__ == "__main__":
    adb_swipe()

你可能感兴趣的:(安卓自动化测试)