Database Reference
In-Depth Information
Figure 5-6. Labeling elements for scripting
Alas, many of the elements on the screen don't have accessibility labels, so you have to
access them through more arcane methods. As a example, let's look at a test that looks
for the zip code button in the toolbar, presses it, and then sees if it gets a good value
back ( Example 5-4 ).
Example 5-4. A sample UIAutomation script
UIALogger.logStart("Find Toolbar");
var target = UIATarget.localTarget();
var window = target.frontMostApp().mainWindow();
window.logElementTree();
var toolbars = window.toolbars();
if (toolbars.length != 1) {
UILogger.logFail("Did not find toolbar");
}
UIALogger.logStart("Find Output View");
var outputViews = window.textViews();
if (outputViews.length == 0) {
UIALogger.logFail("Did not find output textview");
}
var outputView = outputViews[0];
UIALogger.logStart("Find Button");
var buttons = toolbars[0].buttons();
var zipButton = buttons["Zip Code"];
if (zipButton == null) {
UILogger.logFail("Did not find zipcode button");
}
UIALogger.logStart("Test Zipcode Button");
zipButton.tap();
 
Search WWH ::




Custom Search