Skip to content

Commit 95aead0

Browse files
committed
add docs
1 parent 825ae87 commit 95aead0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+751
-0
lines changed

docs/advance-topics/api.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# 常用API
2+
3+
WeAutomator 提供了约 50 个 API,如常用的点击、滑动、查找、等待、登录等,全部 API 文档详见 **工具**-**帮助**-**API**,有详细介绍。
4+
5+
- 点击
6+
7+
```
8+
# 点击图片
9+
click(loc=None, by=DriverType.CV, offset=None, timeout=30, duration=0.05, times=1)
10+
# 点击控件
11+
click(loc=None, by=DriverType.UI, offset=None, timeout=30, duration=0.05, times=1)
12+
# 点击文字
13+
click(loc=None, by=DriverType.OCR, offset=None, timeout=30, duration=0.05, times=1)
14+
# 点击坐标
15+
click(loc=None, by=DriverType.POS, offset=None, timeout=30, duration=0.05, times=1)
16+
```
17+
18+
- 滑动
19+
20+
```
21+
# 根据坐标滑动
22+
slide_pos(pos_from, pos_to=None, pos_shift=None, duration=0)
23+
# 根据图像滑动
24+
slide(loc_from=None, loc_to=None, loc_shift=None, by=DriverType.CV, timeout=30, duration=None)
25+
# 根据控件滑动
26+
slide(loc_from=None, loc_to=None, loc_shift=None, by=DriverType.UI, timeout=30, duration=None)
27+
# 根据文字滑动
28+
slide(loc_from=None, loc_to=None, loc_shift=None, by=DriverType.OCR, timeout=30, duration=None)
29+
```
30+
31+
- 查找
32+
33+
```
34+
# 根据图像查找(查找到返回坐标,未查找到返回None)
35+
find(loc, by=DriverType.CV, timeout=30)
36+
# 根据控件查找(查找到返回坐标,未查找到返回None)
37+
find(loc, by=DriverType.UI, timeout=30)
38+
# 根据文字查找(查找到返回坐标,未查找到返回None)
39+
find(loc, by=DriverType.OCR, timeout=30)
40+
```
41+
42+
- 等待(3.2.0 及以后版本移除)
43+
44+
```
45+
# 在指定的时间等待图像出现(如果没有出现则抛出异常TimeOutError)
46+
wait(locator=None, timeout=20, by=DriverType.CV)
47+
# 在指定的时间等待控件出现(如果没有出现则抛出异常TimeOutError)
48+
wait(locator=None, timeout=20, by=DriverType.UI)
49+
# 在指定的时间等待文字出现(如果没有出现则抛出异常TimeOutError)
50+
wait(locator=None, timeout=20, by=DriverType.OCR)
51+
# 在指定的时间等待图片消失(如果仍然存在则抛出异常TargetStillExistError)
52+
wait_vanish(locator=None, timeout=20, by=DriverType.CV)
53+
# 在指定的时间等待控件出现(如果没有出现则抛出异常TargetStillExistError)
54+
wait_vanish(locator=None, timeout=20, by=DriverType.UI)
55+
# 在指定的时间等待文字出现(如果没有出现则抛出异常TargetStillExistError)
56+
wait_vanish(locator=None, timeout=20, by=DriverType.OCR)
57+
```
58+
59+
- 判断存在(3.2.0 及以后版本移除)
60+
61+
```
62+
# 在指定的时间等待图像出现(存在返回True,不存在返回False)
63+
exists(locator=None, timeout=20, by=DriverType.CV)
64+
# 在指定的时间等待控件出现(存在返回True,不存在返回False)
65+
exists(locator=None, timeout=20, by=DriverType.UI)
66+
# 在指定的时间等待文字出现(存在返回True,不存在返回False)
67+
exists(locator=None, timeout=20, by=DriverType.OCR)
68+
```
69+
70+
- 账号相关
71+
72+
```
73+
# QQ登录
74+
qq_login(acc='', pwd='')
75+
# 微信登录
76+
wechat_login(acc = '', pwd = '')
77+
# 选择和QQ好友一起玩
78+
play_with_qq_friends(locator=None, acc='', pwd='', timeout=240)
79+
# 选择和微信好友一起玩
80+
play_with_wechat_friends(locator = None, acc = '', pwd = '', timeout = 240)
81+
```
82+
83+
- 设备相关
84+
85+
```
86+
# 获取远程数据(苹果设备无此功能)
87+
get_data(platform = PlatformType.OUTER, name="", default_data={})
88+
# 根据xpath获取元素列表
89+
get_elements(xpath, by=DriverType.UI)
90+
# 获取设备当前画面
91+
get_img()
92+
# 获取控件树
93+
get_uitree(by=DriverType.UI)
94+
# 将绝对坐标转换成相对坐标
95+
ratio_transfer(pt)
96+
# 将相对坐标转换成绝对坐标
97+
win_transfer(pt)
98+
# 手机截图
99+
screenshot(label='screenshot', img_path=None, pos=None)
100+
# 获取脚本目录
101+
script_dir()
102+
# 执行adb shell命令
103+
shell(cmd)
104+
# 执行adb shell命令不显示窗口
105+
shell_noshow(cmd)
106+
# 苹果设备将绝对坐标转换成相对坐标
107+
abs2rel(pt)
108+
# 苹果设备将相对坐标转换成绝对坐标
109+
rel2abs(pt)
110+
```
111+
112+
- 智能 monkey
113+
114+
```
115+
# 进行智能探索(Android)
116+
ai_monkey(pkg=None, explore_type=ExploreType.CTRL, timeout=-1, pre_exec=None, web_check=True, keyboard_check=True, restart_interval = 900, other_data=[], qq_data=[], wechat_data=[])
117+
# 进行智能探索(iOS)
118+
ai_monkey(pkg=None, explore_type=ExploreType.UI, timeout=3600, pre_exec=None)
119+
# 停止智能探索(Android)
120+
stop_monkey(ai_key)
121+
```
30.2 KB
Loading
51.6 KB
Loading
107 KB
Loading
187 KB
Loading
29.1 KB
Loading
53.1 KB
Loading
6.14 KB
Loading
164 KB
Loading
106 KB
Loading

0 commit comments

Comments
 (0)