auto.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/8/15
  4. import atomacos
  5. # from atomacos import keyboard
  6. from time import sleep
  7. bundle_id = "com.tencent.xinWeChat"
  8. # 启动应用
  9. atomacos.launchAppByBundleId(bundle_id)
  10. atomator = atomacos.getAppRefByBundleId(bundle_id)
  11. sleep(3)
  12. # 获取当前窗口
  13. wx = atomator.windows()[0]
  14. print(wx)
  15. # 获取输入框
  16. lt = wx.findFirstR(AXRole="AXRadioButton", AXHelp="微信")
  17. print(lt)
  18. # 获取位置参数
  19. lt_position = lt.AXPosition
  20. lt_size = lt.AXSize
  21. # 注意AXPositon得到的坐标是元素左上角的坐标,需要根据实际大小得到元素中心点坐标
  22. lt_click = (lt_position[0] + lt_size[0] / 2, lt_position[1] + lt_size[1])
  23. print(lt_click)
  24. lt.clickMouseButtonLeft(lt_position)
  25. # 输入内容(输入键盘字符,US_keyboard)
  26. # s1 = lt.findFirstR(AXRole='AXTextArea', AXRoleDescription='文本输入区')
  27. s1 = lt.findFirstR(AXRole='AXTextArea', AXLable='搜索')
  28. s1_p = s1.AXPosition
  29. s1_s = s1.AXSize
  30. s1.tripleClickMouse((s1_p[0] + s1_s[0] / 2, s1_p[1] + s1_s[1] / 2))
  31. s1.sendKeys('公众号')