安装 pip install uiautomator2
设备上安装 atx-agent
元素定位工具安装
pip install weditor
执行 python -m weditor
import uiautomator2 as u2
self.d = u2.connect()
#拉取手机数据(示例代码)
def get_hierarchy(self):
hi = self.d.dump_hierarchy()
str01=re.findall(r'<node index="0" text="(.*?)"',hi)
question = []
answer = []
for i in str01:
if len(i)>1:
i = "".join(i.split())
question.append(i)
# question = question[0]
str01=re.findall(r'<node index="1" text="(.*?)"',hi)
for i in str01:
if len(i)>1:
i = "".join(i.split())
answer.append(i)
return((question,answer))