ATOMac简介

atomac是一个支持在mac上做自动化的python库,GitHub地址如下:

https://github.com/pyatom/pyatom

安装

# Python2
sudo easy_install atomac # Python3
pip3 install git+https://github.com/pyatom/pyatom/

使用

1. 启动程序

import atomac
atomac.launchAppByBundleId('com.apple.Automator')

查看bundleID的方法

在应用程序->右键选择包内容->Contents->Info.plist

2. 查看app信息

automator = atomac.getAppRefByBundleId('com.apple.Automator')
print(automator)

输出

<atomac.AXClasses.NativeUIElement AXApplication '自动操作'>

3. 获取应用标题

window = automator.windows()[]
print(window.AXTitle)

输出

未命名

atomac支持获取和操作大部分的元素,可以使用xcode提供的accessibility inspector快速查看各个元素

路径: Xcode -> Open Developer Tools -> Accessibility inspector

4. 获取元素快照列表

window = automator.windows()[]
sheet = window.sheets()[]
print(sheet)

输出:

<atomac.AXClasses.NativeUIElement AXSheet '表单'>

windows是atomac的一种定位方法,用来获取window元素,这里我们获取到了最顶层窗口的元素,然后再用sheets定位方法来获取当前window的元素快照(sheet)

atomac所有的定位方法加上'R'字符,就变成了一个搜索方法(可以添加额外的搜索条件),例如上面的方法我们可以直接改为:

sheet = automator.sheetsR()[]

5. 通过快照获取元素

通过快照我们可以进行元素定位, 这里我们以关闭按钮为例

closeButton = sheet.buttons('关闭')[]
print(closeButton)

输出:

<atomac.AXClasses.NativeUIElement AXButton '关闭'>

支持的元素类型查询方法有:

textAreas
textFields
buttons
windows
sheets
staticTexts
genericElements
groups
radioButtons
popUpButtons
rows
sliders

6. 条件搜索元素

atomac支持findFirst方法,根据属性来进行元素搜索,例如

closeButton = sheet.findFirst(AXRole='AXButton', AXTitle='关闭')

支持的属性可以在Accessibility inspector中查看

findFirst和findFirstR方法返回首个匹配的元素, 如果没有找到匹配的元素则返回None

同时还有findAll和findAllR使用方法相同,返回所以匹配的元素列表,没有匹配的元素则返回空列表

7. 查看元素支持的属性

closeButton = sheet.findFirst(AXRole='AXButton', AXTitle='关闭')
print(closeButton.getAttributes())

输出

['AXRole', 'AXHelp', 'AXEnabled', 'AXWindow', 'AXSize', 'AXTitle', 'AXRoleDescription', 'AXTopLevelUIElement', 'AXFocused', 'AXParent', 'AXPosition', 'AXFrame', 'AXIdentifier']

查看属性值

print(closeButton.AXTitle)

输出

关闭

8. 查看元素支持的操作

print(closeButton.getActions())

输出

['Press']

9. 元素操作

closeButton.Press()

任何支持的操作都可以这样调用

最新文章

  1. [Leetcode] Number of Digit Ones
  2. XML解析、使用TreeView呈现效果
  3. js前端分页
  4. Android多线程文件下载
  5. js 扩展Array支持remove方法
  6. jquery时间倒计时
  7. Xcode6模拟器时BUG导致键盘无法弹出
  8. HW6.29
  9. 查看kafka的group.id
  10. 第一百二十节,JavaScript事件对象
  11. 使用SQLPLUS创建用户名和表空间
  12. 从 MVC 到前后端分离
  13. SQL Server数据库————增删改查
  14. activiti官网实例项目activiti-explorer之扩展流程节点属性2
  15. FineUIMvc随笔(2)怎样在控件中嵌套 HTML
  16. Linux目录结构以及文件操作
  17. matlab练习程序(FAST特征点检测)
  18. lua保留n位小数方法
  19. NHibernate之旅系列文章导航
  20. 使用C#开发一个简单的P2P应用

热门文章

  1. CSS背景颜色透明
  2. 洛谷 P1186 【玛丽卡】
  3. npm tip: go to the package&#39;s home page
  4. Exception in thread &quot;main&quot; NoNodeAvailableException[None of the configured nodes are available
  5. Python-用xlrd模块读取excel,数字都是浮点型,日期格式是数字的解决办法
  6. 错题重错之枪战Maf
  7. python爬虫学习01--电子书爬取
  8. Dynamics CRM Audit Performance Troubleshooting
  9. MySQL 面试题 24 问
  10. Firefox 底部多出了一个白条