Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I want to test my iOS app. It contains dynamically generated UI elemnts. I create all the UI elements programmatically without using the interface builder. To test I need to access them via Automation tool.

I can't at least print them with logElementTree() and I don't know how to access the dynamically generated elements.

If there is any way I can access dynamically generated elements using a script?

This is my code that tries to log the UI elements.

var target = UIATarget.localTarget();

var app = target.frontMostApp();

var window = app.mainWindow();

target.logElementTree();

I further tried using app.mainWindow().logElementTree(); it is also not working.

Any help will be highly appreciated.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Here is the answer. I did it myself. This is the process.

We can use the method delay(int) to pause the test script because of that the script stays alive. Otherwise the script will end before the dynamic UI is drawn.

Now the logElementTree() methods works and we can access the UI elements.

This is how we access the dynamically generated UI elements. In my app first there is connect button and when it is clicked a UI with a text box and a log in button is dynamically drawn.

This is the script to access UI elements.

var target = UIATarget.localTarget(); var app = target.frontMostApp(); app.logElementTree();

//-- select the elements UIALogger.logMessage( "Click the connect button" ); var window = UIATarget.localTarget().frontMostApp().mainWindow().buttons() [0].tap();

UIALogger.logMessage( "Wait for the next UI" ); target.delay( 2 ); target.frontMostApp().logElementTree(); UIALogger.logMessage( "Enter user name" );

UIALogger.logMessage( "Wait for the next UI" ); target.delay( 3 ); target.frontMostApp().logElementTree(); target.frontMostApp().mainWindow().scrollViews()[0].textFields()[0].setValue("admin"); UIALogger.logMessage( "Dismiss the keyboard" ); var name = UIATarget.localTarget().frontMostApp().keyboard().buttons()["done"].tap();

Hope this helps for someone

share|improve this answer
    
Is there a way to retrieve all the controls available in a screen during automation . To be more specific I want to store the content of the logElementTree onto some variable how to do so ?? – Prabhu Konchada Jun 10 at 7:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.