Search code examples
iphoneiosios-ui-automation

How to access the element of second page in UI automation (iPhone)?


My app has a main screen where i have button to go to login screen. On pressing login button it goes to second screen which is login screen. In the login screen i have a submit button which is inside a table view. I want to tap this Submit. What approach i should use. Or more precisely in same java script hot to access the elements of second scree.


Solution

  • First you have to ensure that the button is accessable. Either set the Accessability property in Interface Builder (Identity Inspector - last Tab) and give the button an appropriate Accessability Label. If you don't use Interface Builder you can set the property on the button programaticaly.

    Now in the script you can call

    mainWindow.buttons()["name of the accessability label"].tap();
    

    mainwindow is:

    var target = UIATarget.localTarget();
    var application = target.frontMostApp();
    var mainWindow = application.mainWindow();
    

    Make also sure that the button is visible. The button has to be the deepest element in the view hierarchie which is marked accessable. If the view containing the button is enabled as accessable, it would hide the accessability of the button (which is a subview).

    You can log all visible elements in the screen by

    mainwindow.logElementTree();
    

    Moreover, you always can use one single script. The mainWindow.elements() references the view which is shown at a certain moment.