1

我需要获取元素的坐标 {X,Y} 以便在其上生成点击事件(我不能通过使用“点击”来做到这一点,因为系统事件有问题并返回:“缺失值”) . 我将使用这些坐标将它们传递给模拟鼠标单击的命令行工具。

我怎样才能做到这一点?

4

1 回答 1

3

你能得到ui元素的属性吗?我认为即使您实际上无法单击它也可以。其中一个属性应该是“位置”,另一个是“大小”。这两件事应该可以帮助您找到屏幕坐标,以便您可以单击元素。

例如尝试这个并查看属性...

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}
于 2012-10-16T22:13:11.860 回答