现在,我正在从事applescript自动化项目。我找不到在弹出式窗口上单击按钮的方法。 (我的系统是macos sierra 10.12.6)请看图片:accessibility inspector screenshot of the button
该按钮的父母是
<empty desctiption> (popover) [_NSPopoverWindow]
现在我没有找到引用此按钮的方法。这是我尝试过的:
tell application "System Events"
tell process "NordVPN"
click menu bar item 1 of menu bar 2 --open the popover window to access the button on the window
delay 0.5
--get the entire contents of menu bar 2
--click (button whose title is "Preferences")
--click button 1 of menu 1 of menu bar item 1 of menu bar 2
--click button 1 of NSPopover of menu bar item 1 of menu bar 2
--click button 1 of NSPopover of menu bar 2
--click button 1 of popover of menu bar item 1 of menu bar 2
click button 1 of _NSPopoverWindow of menu bar item 1 of menu bar 2
--click button 1 of window 1 of menu bar item 1 of menu bar 2
--click button 1
end tell
end tell
他们都失败了。并且无法在Google和stackoverflow上找到有用的信息。希望有人能帮助我!
GUI脚本编写的问题始终是确定GUI元素的层次结构,以便您可以正确地引用所需的GUI元素。从您提供的屏幕截图中,我将首先尝试以下操作:
tell application "System Events"
tell process "NordVPN"
tell second menu bar
tell first button
click --open the popover window to access the button on the window
delay 0.5
tell first pop over
tell button "Preferences"
click
end tell
end tell
end tell
end tell
end tell
end tell
如果不起作用,则必须使用每个给定元素的UI Elements
引用或entire contents
属性在层次结构中向上移动。例如,您可以说:
tell application "System Events"
tell process "NordVPN"
tell second menu bar
tell first button
click --open the popover window to access the button on the window
delay 0.5
tell first pop over
-- to get a list of all the contents of the the popover
entire contents
-- to get the immediate (first level) contents of the popover
UI elements
end tell
end tell
end tell
end tell
end tell
两者都会在脚本编辑器日志中提供弹出式菜单元素的列表。然后,您可以对元素进行实验,以找到所需元素的路径。
GUI脚本始终是一个反复试验的过程;这只会帮助您专注于尝试什么。