如何使用adb命令像手指一样进行拖放操作?

问题描述 投票:0回答:1

我想使用 adb 命令来创建类似应用程序中自动单击的功能。 在我问这个问题之前,我已经尝试过 selenium 和 appium。他们都不能解决我的问题。这个应用程序太奇怪了,当你点击一百次时,它不会让你找到 UI 元素。因此,我只能尝试使用adb命令来实现我的项目。

在这个应用程序中,整个屏幕上您只能看到三个卡片盒。每个卡盒具有完全相同的宽度和高度,每个卡盒之间有空间。只有向上滚动,才会弹出下一个卡片盒。
我想像使用手指一样执行精确的滚动链效果。用手指按住屏幕,向上或向下拖动,然后抬起手指,不会出现过度滚动的情况。

我测试了一些类似

adb shell input swipe {x1} {y1} {x1} {y1 + y} {duration}
的代码,但无法实现我所说的效果。
问题是我只想用 adb cammand 精确地滚动远处,然后每次我都可以精确地点击第一个卡盒。

我在 python 中测试了我的代码,并有一些限制。
1.不允许使用Appium。
2.不允许使用Selenium。

还有其他解决办法吗?

python android adb
1个回答
0
投票

其中一个AndroidViewClient/culebra示例正是拖放操作,不完全是使用adb而是关闭。

我将源代码留在这里,因为它很简单

#! /usr/bin/env python3

from com.dtmilano.android.viewclient import ViewClient

helper = ViewClient.view_client_helper()
oid = helper.ui_device.find_object(ui_selector="desc@YouTube").oid
t, l, r, b = helper.ui_object.get_bounds(oid=oid)
s_x = int(l + (r - l)/2)
s_y = int(t + (b - t)/2)
e_x = 300
e_y = 700
helper.ui_device.drag(s_x, s_y, e_x, e_y, 50)

但您也可以在这里找到它。

观看其实际操作的截屏视频也可在 launcher-drag-youtube-icon.gif 处获取(太大,无法在此处上传)。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.