我需要获取元素的坐标{X,Y}以便在其上生成click事件(我不能通过使用“click”来执行此操作,因为System Events在执行此操作时遇到问题并返回:“值”)。我将使用这些坐标将它们传递给模拟鼠标单击的命令行工具。
我怎样才能做到这一点?
答案 0 :(得分:2)
你能获得ui元素的属性吗?我想你甚至可以实际点击它。其中一个属性应该是“position”,另一个属性是“size”。这两件事应该可以帮助您找到屏幕坐标,以便您可以单击该元素。
例如,尝试这个并查看属性......
tell application "System Events"
tell process "Safari"
properties of UI element 1 of window 1
end tell
end tell
因此,如果我想知道该元素中间的坐标,以便您可以单击它,这将为您提供点击位置的x和y坐标...
tell application "System Events"
tell process "Safari"
tell UI element 1 of window 1
set p to position
set s to size
end tell
end tell
end tell
set xCoordinate to (item 1 of p) + (item 1 of s) / 2
set yCoordinate to (item 2 of p) + (item 2 of s) / 2
return {p, s, xCoordinate, yCoordinate}