python-uiautomator2/tasks/wechat/__init__.py

61 lines
1.6 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):
2025-02-01 14:41:23 +08:00
clear_btn = d.xpath('//*[@resource-id="com.tencent.mm:id/mdd"]/android.widget.RelativeLayout[1]')
2024-08-28 03:19:41 +08:00
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()
2024-08-28 04:00:12 +08:00
def get_last_chat_text(d: Device):
selector = (d.xpath('//*[@resource-id="com.tencent.mm:id/bn1"]')
.child('//*[@resource-id="com.tencent.mm:id/bkl"]'))
elements = selector.all()
if len(elements) > 0:
last_element = elements[-1]
print(last_element.text)