如何使用 JXA 单击 UI 元素

How to click UI element using JXA

请告诉我如何在应用程序中单击点坐标 window? 我尝试使用 JXA 技术 UI 在 OSX 10.10 上自动化我的应用程序。 在文档中我发现可以使用点击事件。我是 JXA 的初学者,无法找到如何拨打电话。 我在脚本编辑器中尝试的代码片段:

var app = Application('my_application_path')
app.window.click.at('{100,100}')

感谢您的帮助

您可以使用系统事件应用程序与应用程序的用户界面交互。这是一个在 Safari 中点击特定坐标的脚本:

// Activate Safari, so you will be able to click like a user

Application("Safari").activate()

// Access the Safari process of System Events

var SystemEvents = Application("System Events")
var Safari = SystemEvents.processes["Safari"]

// Call the click command, sending an array of coordinates [x, y]

Safari.click({ at: [300, 100] })

如果要单击特定按钮(或用户界面的其他元素),则单击该特定元素更为合适。例如:

// Click the third button of Safari's first window to minimize it

Safari.windows[0].buttons[2].click()

要了解可以与哪些用户界面元素交互以及如何交互,请查看系统事件脚本词典中的流程套件。要打开词典,请在脚本编辑器的菜单栏中选择 Window > 库,然后选择 select 库中的系统事件 window。

https://github.com/dtinth/JXA-Cookbook/wiki/System-Events#clicking-menu-items 例如:

var fileMenu = proc.menuBars[0].menuBarItems.byName('File');