search_key_mac.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/2/20
  4. import time
  5. import atomac
  6. class SearchKey:
  7. @classmethod
  8. def start_wechat(cls):
  9. # 启动应用并获取应用信息
  10. bundle_id = "com.tencent.xinWeChat"
  11. print("启动微信")
  12. atomac.launchAppByBundleId(bundle_id)
  13. automator = atomac.getAppRefByBundleId(bundle_id)
  14. time.sleep(1)
  15. # 获取当前应用window
  16. window = automator.windows()[0]
  17. print(f"当前应用window:{window.AXTitle}")
  18. # 查找聊天按钮
  19. print("查找聊天按钮")
  20. chat_btn = window.findFirstR(AXHelp="微信", AXRole="AXRadioButton")
  21. # print(chat_btn.getAttributes())
  22. # 点击聊天按钮,展开聊天列表
  23. print("点击聊天按钮")
  24. chat_btn.Press()
  25. time.sleep(1)
  26. # # 查找文件传输助手
  27. # print("查找文件传输助手")
  28. # chat_help = window.findFirstR(AXRole="AXCell")
  29. # print(f"文件传输助手:{chat_help}")
  30. # print("点击文件传输助手")
  31. # chat_help_position = chat_help.AXSize
  32. # chat_help.clickMouseButtonLeft(chat_help_position)
  33. print("查找微信指数小程序消息")
  34. weixinzhishu = window.findFirstR(AXValue="微信指数", AXRole="AXStaticText")
  35. print(f"微信指数小程序消息:{weixinzhishu}")
  36. print("点击微信指数小程序消息")
  37. weixinzhishu_position = weixinzhishu.AXSize
  38. print(weixinzhishu_position)
  39. # weixinzhishu.clickMouseButtonLeft(weixinzhishu_position)
  40. # chat_msg.clickMouseButtonLeft((780, 450))
  41. # chat_msg_position.Press()
  42. time.sleep(3)
  43. if __name__ == "__main__":
  44. SearchKey.start_wechat()