applescript - 如何使用 AppleScript 在 Safari 网络浏览器中单击此层次结构的选项卡
解决方案
The easiest way I find to obtain a reference to a UI element from an object hierarchy is to use System Events' click at
command, e.g.
tell application "System Events" to click at {300, 400}
If you run this command in Script Editor, it returns an object reference to whatever it finds at the coordinates you specify, in this case {300, 400}
.
Therefore, what you can do is to hover the mouse over your "Start"
object and obtain the mouse's coordinates. This can be done by starting a screen capture using ⌘</kbd>⇧</kbd>4, which brings up a set of crosshairs from which you can read the coordinates of the mouse cursor. Then press ESC to cancel the screen capture, and use those coordinates to run a click at
command (make sure the Script Editor window doesn't obscure the "Start"
tab when you run the command).
Then, once you run it, the object reference (if it has one, which it ought to if it appears in the Accessibility Inspector) will appear in the results pane at the bottom of the Script Editor window, which you can copy and paste. Here's an example:
Here, my mouse cursor is hovering over the tab in Safari in which I'm typing this answer. I obtained the coordinates as being {500, 73}
, then ran the command you see in Script Editor. At the bottom is the object reference to the tab. Note that the mouse doesn't need to remain hovering over the object in question as the coordinates specified will be used to issue the click and obtain a reference; I just kept my mouse there for illustrative purposes.
推荐阅读
- reactjs - Redux 状态变量显示为未定义
- swiftui - 当应用程序处于后台时如何控制`Timer.publish()`
- excel - 将表格动态过滤到在线 excel 文件中的另一个工作表
- coq - 虽然预计在 Coq 中它的类型为“forall...”
- c# - 如何重新绘制面板的某些部分/或使用两个面板相互叠加,顶部的面板具有透明背景?
- android - Xamarin 表单获取当前位置需要更多时间
- android - 修复 Landroid/view/MotionEvent 不兼容问题
- rust - 从 Rust 中的函数返回迭代器返回“大小......在编译时无法知道”
- typescript - 在间隙前一天完全绘制线
- python - 从 Trax 循环中选择任务