本文介绍了如何使用JXA单击UI元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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}')

谢谢您的帮助

推荐答案

您可以使用系统事件"应用程序与应用程序的用户界面进行交互.这是一个在Safari中点击某些坐标的脚本:

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()

要了解可以与哪些用户界面元素进行交互以及如何进行交互,请查看系统事件脚本字典中的Processes Suite.要打开字​​典,请在脚本编辑器"的菜单栏中,选择窗口">库",然后在库"窗口中选择系统事件".

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.

这篇关于如何使用JXA单击UI元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:45