如何非坐标定位GlobalProtect的Sign In按钮实现自动化点击?
定位GlobalProtect登录窗口的"Sign In"按钮方法
先查清楚按钮的UI属性
首先得拿到这个按钮的具体UI属性——直接用标题失效,大概率是控件层级或属性名称匹配不对。运行下面的脚本,它会输出GlobalProtect前台窗口里所有UI元素的详细信息:
tell application "System Events" tell front window of application process "GlobalProtect" get entire contents end tell end tell
在输出结果里找带有"Sign In"文本的按钮条目,重点记下AXIdentifier、AXLabel这类能唯一标识它的属性值。
用唯一属性定位点击
方式1:通过AXIdentifier定位
如果查到按钮的AXIdentifier是类似"sign-in-button"的唯一值,用下面的脚本点击:
tell application "System Events" click button 1 of front window of application process "GlobalProtect" whose AXIdentifier is "sign-in-button" end tell
方式2:通过AXLabel精准匹配
如果按钮的AXLabel就是"Sign In",试试直接指定进程范围查找,避免窗口层级问题:
tell application "System Events" tell application process "GlobalProtect" click (every button whose AXLabel is "Sign In") end tell end tell
方式3:遍历控件兜底
要是上面的方法都不行,就用遍历的方式逐个检查窗口控件,找到目标按钮就点击:
tell application "System Events" set loginWindow to front window of application process "GlobalProtect" repeat with elem in entire contents of loginWindow if role of elem is "button" and value of attribute "AXLabel" of elem is "Sign In" then click elem exit repeat end if end repeat end tell
⚠️ 注意:运行这类脚本需要给你的脚本工具(比如脚本编辑器、Automator)开启系统设置里的「辅助功能」权限,不然会报错无法操作UI。
内容的提问来源于stack exchange,提问作者Chenulu Peri
相关产品推荐
相关产品推荐

