From 7ffd4147ea31da88a2d3b835dd7af7bc92147eff Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Wed, 28 Aug 2024 03:35:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 1 + tasks/wechat/__init__.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 05a0b4f..4c6f1f9 100644 --- a/main.py +++ b/main.py @@ -125,6 +125,7 @@ async def wechat_search_task(item: WechatSearchInput): tasks.wechat.click_search_btn(d) tasks.wechat.input_search_text(d, item.text) tasks.wechat.click_search_result(d) + tasks.wechat.input_chat_text(d, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) if __name__ == '__main__': uvicorn.run('main:app', host='0.0.0.0', port=8000, reload=True) diff --git a/tasks/wechat/__init__.py b/tasks/wechat/__init__.py index 574342c..ea3f353 100644 --- a/tasks/wechat/__init__.py +++ b/tasks/wechat/__init__.py @@ -26,7 +26,7 @@ def input_search_text(d: Device, text: str): def click_search_result(d: Device): selector = d.xpath('//*[@resource-id="com.tencent.mm:id/kbo"]') - selector.wait(timeout=3) + selector.wait(timeout=5) elements = selector.all() print(elements) @@ -34,3 +34,17 @@ def click_search_result(d: Device): elements[0].click() else: logging.warning("未找到组件") + + +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()