首先我们需要明确下需求目标,我们的需求很简单,就是使用python脚本完成需要我们自己完成的很多
重复的操作,即便中间存在一定的重复操作之外,但是整体操作是完全重复和符合规则的。
设计思路
我的设计思路很简单,就是用Python使用 ADB 命令,模拟人为的点击输入等操作。
import os
import time
# 点击事件
def click(x, y):
cmd = "adb shell input tap {x1} {y1}".format(
x1=x,
y1=y
)
os.system(cmd)
# 输入用户名
def input_name():
os.system("adb shell input text 1")
# 滑动屏幕 根据屏幕数判断需要滑动的次数
def swipe():
os.system("adb shell input swipe 100 410 100 5")
# 获取当前名目的所有控件布局 并写入到xml文件中
def screen_xml():
os.system("adb shell uiautomator dump /sdcard/ui.xml")
time.sleep(3)
# 读取xml文件,判断是否存在"重新选择"的按钮,如果不存在,输入文本
def read_xml():
os.system("adb pull /sdcard/ui.xml .")
f = open("./ui.xml", "r", encoding="UTF-8")
s = f.read()
if s.find("id/res_tv_to_gallery") == -1:
print("不存在")
input_name()
else:
print("存在")
click_re()