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