python-uiautomator2/tasks/wechat/__init__.py

51 lines
1.2 KiB
Python
Raw Normal View History

2024-08-28 03:19:41 +08:00
import logging
from uiautomator2 import Device
def click_search_btn(d: Device):
selector = d.xpath('//*[@resource-id="com.tencent.mm:id/h5n"]')
if selector.exists:
selector.click()
else:
logging.warning("未找到组件")
def input_search_text(d: Device, text: str):
clear_btn = d.xpath('//*[@resource-id="com.tencent.mm:id/nhn"]')
if clear_btn.exists:
clear_btn.click()
selector = d.xpath('//*[@resource-id="com.tencent.mm:id/mdd"]')
if selector.exists:
selector.set_text(text)
else:
logging.warning("未找到组件")
def click_search_result(d: Device):
selector = d.xpath('//*[@resource-id="com.tencent.mm:id/kbo"]')
2024-08-28 03:35:30 +08:00
selector.wait(timeout=5)
2024-08-28 03:19:41 +08:00
elements = selector.all()
print(elements)
if len(elements) > 0:
elements[0].click()
else:
logging.warning("未找到组件")
2024-08-28 03:35:30 +08:00
def input_chat_text(d: Device, text: str):
selector = d.xpath('//*[@resource-id="com.tencent.mm:id/bkk"]')
selector.wait(timeout=5)
if selector.exists:
selector.set_text(text)
else:
logging.warning("未找到组件")
selector = d.xpath('//*[@resource-id="com.tencent.mm:id/bql"]')
selector.wait(timeout=1)
selector.click()