Contents
  1. 1. uiautomator
  2. 2. uiautomator2
  3. 3. 使用开发者模式获取鼠标坐标

https://developer.android.google.cn/studio/releases/platform-tools?hl=zh-cn#downloads.html

uiautomator

获取控件信息

连接(Nox)
C:\Users\Manhua\AppData\Local\Android\Sdk\platform-tools\adb.exe connect 127.0.0.1:62001
连接(Mumu root权限开启)
C:\Users\Manhua\AppData\Local\Android\Sdk\platform-tools\adb.exe connect 127.0.0.1:7555

2.截图后鼠标指向即可 (获取组件xml和位置信息)
C:\Users\Manhua\AppData\Local\Android\Sdk\tools\bin\uiautomatorviewer.bat

uiautomator2

pip install -U uiautomator2
python -m uiautomator2 init
pip install weditor==0.6.4
python -m weditor

使用开发者模式获取鼠标坐标

adb.exe install C:\Users\Manhua\Downloads\xxx.apk

docker run –privileged -d -p 6080:6080 -p 5554:5554 -p 5555:5555 -p 4723:4723 –name android-12 budtmo/docker-android-x86-12.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import os
import time


def runADB(cmd, wait_time=1):
os.system(cmd)
time.sleep(wait_time)


def listDev():
runADB("adb devices", 0)


def putFile(local_path, remote_path):
cmd = "adb push {local_path} /sdcard/{remote_path}"
runADB(cmd.format(**locals()))


def getFile(remote_path, local_path):
cmd = "adb pull /sdcard/{remote_path} {local_path}"
runADB(cmd.format(**locals()))


def installApk(local_apk_path):
cmd = "adb install {local_apk_path}"
runADB(cmd.format(**locals()))


def tap(x, y, wait_time=1):
cmd = "adb shell input tap {x} {y}"
runADB(cmd.format(**locals()), wait_time)


def longTap(x, y):
swipe(x, y, x, y, 1000)


def swipe(startX, endX, startY, endY, timeToSwipe):
cmd = "adb shell input swipe {startX} {startY} {endX} {endY} {timeToSwipe}"
runADB(cmd.format(**locals()))


def swipeUp():
swipe(100, 400, 100, 100, 300)


def swipeDown():
swipe(100, 100, 100, 400, 300)


def keyevent(num):
cmd = "adb shell input keyevent {num}"
runADB(cmd.format(**locals()))


def back():
keyevent(4)


def home():
keyevent(3)


def enter():
keyevent(66)


def esc():
keyevent(111)


def intent(intent_name, paras):
cmd = "adb shell am start -a {intent_name} -d {paras}"
runADB(cmd.format(**locals()))


def call(phone):
intent("android.intent.action.CALL", phone)


def web(url):
intent("android.intent.action.VIEW", url)


# {包名}/.{主Activity名}
def launch(app):
cmd = "adb shell am start -n {app} "
runADB(cmd.format(**locals()))


def listPkg():
cmd = "adb shell pm list package "
runADB(cmd)


def screenshot(filename):
cmd = "adb shell screencap /sdcard/{filename}.png "
runADB(cmd.format(**locals()))


def screenshotToPC(local_path, filename):
screenshot(filename)
getFile("/sdcard/"+filename+".png", local_path)
cmd = "adb shell rm /sdcard/{filename}.png"
runADB(cmd.format(**locals()))


def ershida():
# tap(360, 930) # 人机
# loop
tap(360, 980, 5) # 开始

tap(360, 710, 5) # A
tap(360, 840, 5) # B
tap(360, 710, 5) # A
tap(360, 840, 5) # B
tap(360, 710, 5) # A
tap(360, 930, 3) # 继续挑战

# tap(360, 710, 5) # A
# tap(360, 840, 5) # B
# tap(360, 980, 5) # C
# tap(360, 1120, 5) # D


def ershida10():
tap(360, 930) # 人机
for i in range(10):
print(i)
ershida()


if __name__ == '__main__':
runADB("adb version", 0)

# from PhoneADB import *