Search code examples
iosui-automationios-ui-automation

How to access children of mainWindow for UI Automation in Xcode


I have a structure in the mainWindow() of my application as follows:

enter image description here

Within the children directory of the UIAWindow near the top of the image, I am trying to access Item 1, where it is a UIAButton.

This structure is generated from

#import "tuneup/tuneup.js"

goAbout = function(target, app)
{
    UIATarget.localTarget().frontMostApp().mainWindow().logElementTree();

};

test("go about", goAbout);

If I add .button() or [1] it raises an exception, so I cannot do something like so

...
UIATarget.localTarget().frontMostApp().mainWindow().buttons().logElementTree();

What can I do to access the object within the children subdirectory of the UIAWindow?


Solution

  • You can access that button by adding .buttons()[0]. The

    UIATarget.localTarget().frontMostApp().mainWindow().buttons();
    

    expression returns a javascript array (which has a 0 based indexing).

    Here you can find a rather usable documentation: https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/UIAutomationRef/UIAutomationRef.pdf

    Anyway studying this plist is not the most convenient method to explore your object hierarchy. I prefer to check instruments output directy. (Or standard output, if you run instruments from command line.)