This commit is contained in:
HuangHai
2026-01-17 07:21:21 +08:00
parent a3a77b8333
commit f6fb2ab97f
8 changed files with 97 additions and 18 deletions

1
.idea/vcs.xml generated
View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>
</project> </project>

View File

@@ -84,8 +84,19 @@ async def open_mini_program():
await asyncio.sleep(2) await asyncio.sleep(2)
# 4. 输入搜索内容
logger.info("输入搜索内容: 艾特吉易充") logger.info("输入搜索内容: 艾特吉易充")
try:
d.set_input_ime(True)
except Exception as e:
logger.warning(f"启用 FastInputIME 失败: {e}")
try:
search_bar_x, search_bar_y = int(w * 0.4), int(h * 0.08)
d.click(search_bar_x, search_bar_y)
await asyncio.sleep(1.5)
except Exception as e:
logger.warning(f"点击搜索框以获取焦点失败: {e}")
try: try:
logger.info("尝试输入文字: 艾特吉易充") logger.info("尝试输入文字: 艾特吉易充")
d.send_keys("艾特吉易充") d.send_keys("艾特吉易充")
@@ -101,6 +112,11 @@ async def open_mini_program():
await asyncio.sleep(3) await asyncio.sleep(3)
try:
d.set_input_ime(False)
except Exception as e:
logger.warning(f"恢复系统输入法失败: {e}")
# 5. 点击小程序 # 5. 点击小程序
logger.info("点击搜索结果中的小程序...") logger.info("点击搜索结果中的小程序...")
# 这里由于没有模板,先使用坐标点击作为第一版的测试逻辑 (通常第一个结果在 50%, 18%) # 这里由于没有模板,先使用坐标点击作为第一版的测试逻辑 (通常第一个结果在 50%, 18%)

View File

@@ -21,17 +21,40 @@ async def open_mini_program():
d.app_start("com.tencent.mm", stop=True) d.app_start("com.tencent.mm", stop=True)
await asyncio.sleep(5) await asyncio.sleep(5)
# 2. 点击搜索按钮 (坐标适配大部分微信版本)
logger.info("点击搜索按钮...") logger.info("点击搜索按钮...")
w, h = d.window_size() w, h = d.window_size()
d.click(int(w * 0.84), int(h * 0.08)) d.click(int(w * 0.84), int(h * 0.08))
await asyncio.sleep(2) await asyncio.sleep(2)
# 3. 输入搜索内容
logger.info("输入搜索内容: 特来电") logger.info("输入搜索内容: 特来电")
try:
d.set_input_ime(True)
except Exception as e:
logger.warning(f"启用 FastInputIME 失败: {e}")
try:
search_bar_x, search_bar_y = int(w * 0.4), int(h * 0.08)
d.click(search_bar_x, search_bar_y)
await asyncio.sleep(1.5)
except Exception as e:
logger.warning(f"点击搜索框以获取焦点失败: {e}")
try:
d.send_keys("特来电") d.send_keys("特来电")
except Exception as e:
logger.warning(f"直接 send_keys 失败: {e}")
try:
d(focused=True).set_text("特来电")
except Exception as e2:
logger.error(f"文字输入彻底失败: {e2}")
await asyncio.sleep(3) await asyncio.sleep(3)
try:
d.set_input_ime(False)
except Exception as e:
logger.warning(f"恢复系统输入法失败: {e}")
# 4. 点击搜索结果中的第一个小程序 # 4. 点击搜索结果中的第一个小程序
logger.info("点击搜索结果中的小程序...") logger.info("点击搜索结果中的小程序...")
# 这里的坐标可能需要根据实际情况调整,先参考 YeLiTe 的实现 # 这里的坐标可能需要根据实际情况调整,先参考 YeLiTe 的实现

View File

@@ -123,16 +123,25 @@ async def open_mini_program():
# 点击后给予一定的加载时间 # 点击后给予一定的加载时间
await asyncio.sleep(2) await asyncio.sleep(2)
# 2. 直接尝试输入内容 (既然已经看到了搜索界面,我们不再进行严格的特征校验) # 2. 确保输入法和焦点正常,然后输入搜索内容
logger.info("准备输入搜索内容: 新电途") logger.info("准备输入搜索内容: 新电途")
# 启用 u2 快速输入法 (使用更新的方法名) # 尝试启用 FastInputIME提升 send_keys 的成功率
# d.set_input_ime(True) try:
logger.info("尝试启用 FastInputIME 输入法...")
d.set_input_ime(True)
logger.info("FastInputIME 已启用.")
except Exception as e:
logger.warning(f"启用 FastInputIME 失败: {e}")
# 尝试点击搜索框位置以确保获取焦点 (通常在顶部居中偏左) # 再点击一次搜索框,确保真正拿到输入焦点
# search_bar_x, search_bar_y = int(w * 0.4), int(h * 0.08) try:
# d.click(search_bar_x, search_bar_y) search_bar_x, search_bar_y = int(w * 0.4), int(h * 0.08)
# await asyncio.sleep(1.5) # 稍微多等一会儿让输入法准备好 logger.info(f"再次点击搜索框以获取焦点: ({search_bar_x}, {search_bar_y})")
d.click(search_bar_x, search_bar_y)
await asyncio.sleep(1.5)
except Exception as e:
logger.warning(f"点击搜索框以获取焦点失败: {e}")
# 直接发送按键 # 直接发送按键
try: try:
@@ -151,12 +160,17 @@ async def open_mini_program():
logger.info("set_text 指令已发送.") logger.info("set_text 指令已发送.")
except Exception as e2: except Exception as e2:
logger.error(f"文字输入彻底失败: {e2}") logger.error(f"文字输入彻底失败: {e2}")
# 最后的尝试:切换回默认输入法(有时 FastInputIME 会卡住)
# d.set_fastinput_ime(False)
# d.send_keys("新电途")
await asyncio.sleep(3) await asyncio.sleep(3)
# 尝试恢复系统默认输入法,避免后续人工操作受影响
try:
logger.info("尝试恢复系统默认输入法...")
d.set_input_ime(False)
logger.info("已恢复系统默认输入法.")
except Exception as e:
logger.warning(f"恢复系统默认输入法失败: {e}")
# # 兜底点击:点击搜索结果的第一项位置 (x=50%, y=18%) # # 兜底点击:点击搜索结果的第一项位置 (x=50%, y=18%)
# res_x, res_y = int(w * 0.5), int(h * 0.18) # res_x, res_y = int(w * 0.5), int(h * 0.18)
# logger.info(f"尝试坐标点击第一项: ({res_x}, {res_y})") # logger.info(f"尝试坐标点击第一项: ({res_x}, {res_y})")

View File

@@ -58,17 +58,40 @@ async def open_mini_program():
d.app_start("com.tencent.mm", stop=True) d.app_start("com.tencent.mm", stop=True)
await asyncio.sleep(5) await asyncio.sleep(5)
# 2. 点击搜索按钮 (坐标适配大部分微信版本)
logger.info("点击搜索按钮...") logger.info("点击搜索按钮...")
w, h = d.window_size() w, h = d.window_size()
d.click(int(w * 0.84), int(h * 0.08)) d.click(int(w * 0.84), int(h * 0.08))
await asyncio.sleep(2) await asyncio.sleep(2)
# 3. 输入搜索内容
logger.info("输入搜索内容: 驿来特") logger.info("输入搜索内容: 驿来特")
try:
d.set_input_ime(True)
except Exception as e:
logger.warning(f"启用 FastInputIME 失败: {e}")
try:
search_bar_x, search_bar_y = int(w * 0.4), int(h * 0.08)
d.click(search_bar_x, search_bar_y)
await asyncio.sleep(1.5)
except Exception as e:
logger.warning(f"点击搜索框以获取焦点失败: {e}")
try:
d.send_keys("驿来特") d.send_keys("驿来特")
except Exception as e:
logger.warning(f"直接 send_keys 失败: {e}")
try:
d(focused=True).set_text("驿来特")
except Exception as e2:
logger.error(f"文字输入彻底失败: {e2}")
await asyncio.sleep(3) await asyncio.sleep(3)
try:
d.set_input_ime(False)
except Exception as e:
logger.warning(f"恢复系统输入法失败: {e}")
# 4. 点击搜索结果中的第一个小程序 # 4. 点击搜索结果中的第一个小程序
logger.info("点击搜索结果中的小程序...") logger.info("点击搜索结果中的小程序...")
d.click(int(w * 0.5), int(h * 0.18)) d.click(int(w * 0.5), int(h * 0.18))

View File

@@ -0,0 +1,4 @@
import uiautomator2 as u2
d = u2.connect()
d.set_input_ime(True)