How to click UI element using JXA

六眼飞鱼酱① 提交于 2019-12-08 03:35:02

问题


Please tell me how do I click in point coordinates in application window? I trying to UI automate my application on OSX 10.10 using JXA technology. In documentation I found that it's possible using click at event. By I'am beginner of JXA and cant find how make a call. Code snippet which I tried in Script Editor:

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

Thank you for help


回答1:


You can interact with an application's user interface using the System Events application. Here is a script that clicks at certain coordinates in 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] })

If you want to click a specific button (or other element of the user interface), it is more appropriate to click that specific element. For example:

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

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

To learn what user interface elements can be interacted with and how, check out the Processes Suite in System Events' scripting dictionary. To open the dictionary, in Script Editor's menu bar, choose Window > Library, then select System Events in the Library window.




回答2:


See https://github.com/dtinth/JXA-Cookbook/wiki/System-Events#clicking-menu-items For example:

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


来源:https://stackoverflow.com/questions/29081723/how-to-click-ui-element-using-jxa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!