First you need to make sure the button is available. Or set the Accessability property in Interface Builder (Identity Inspector - the last tab) and give the button the appropriate accessibility label. If you are not using Interface Builder, you can set the property on the button programmatically.
Now in the script you can call
mainWindow.buttons()["name of the accessability label"].tap();
mainwindow:
var target = UIATarget.localTarget(); var application = target.frontMostApp(); var mainWindow = application.mainWindow();
Make sure the button is visible. The button should be the deepest element in the hierarchy of views that is marked as available. If the view containing the button is included as accessible, this will hide the availability of the button (which is a preview).
You can register all visible elements on the screen with
mainwindow.logElementTree();
In addition, you can always use one single script. MainWindow.elements () refers to the view that is being displayed at a particular moment.
source share