I'm just starting out with UI Automation for my iOS application, and I already have problems. I can’t attach the screenshots, so I’ll do my best to describe my scenario.
I am creating for iOS 6.0 and using a storyboard. The application launches on the screen with a navigation controller. The root view controller contains the main view, which has 1 sub-UIView that occupies the bottom 60% of the screen and the segmented control that is above this view. I managed to configure the availability of the main view (shortcut "mainview"). Then I can find this element in my test without any problems. However, now I have problems finding a segmented controller. So I decided to infer the length of "elements ()" and "segementedControls ()" from my "mainview" element, and the length of each array is 0. So somehow, when my application starts in the test, it says -elements on my main view.
One more note: I could not find the accessibility section in the identification inspector of the storyboard editor for the segmented control. However, I temporarily added a button to my main view and configured it with an accessibility label to check if calls to elements () or buttons () would subsequently display an element for the main view when performing my test, but these arrays were still returning as empty , even with a button.
Here is my script:
var target = UIATarget.localTarget();
var app = target.frontMostApp();
function selectListView() {
var testName = "selectListView";
UIALogger.logStart(testName);
var view = app.mainWindow().elements()["mainview"];
if (!view.isValid()) {
UIALogger.logFail("Could not locate main view");
}
UIALogger.logMessage("Number of elements for sub element: " + view.elements().length);
var segmentedControl = view.segmentedControls()[0];
if (!segmentedControl.isValid()) {
UIALogger.logFail("Could not locate segmented control on physician collection parent view");
}
var listButton = segmentedControl.buttons()[1];
if (!listButton.isValid()) {
UIALogger.logFail("Could not locate list button on segemented controller on physician collection parent view");
}
UIALogger.logMessage("Tapping List button on physician collection view segmented control");
listButton.tap();
UIALogger.logPass(testName);
}
selectListView();
Any help is greatly appreciated.
EDIT: script , initWithCoder ( , ) - , :
function traverse(root, name) {
if (root.name() == name) {
return root;
}
var elements = root.elements();
for (var i = 0; i < elements.length; i++) {
var e = elements[i];
var result = traverse(e, name);
if(result != null) {
return result;
}
}
return null;
}
function selectListView() {
var testName = "selectListView";
var segmentedControl = traverse(UIATarget.localTarget().frontMostApp().mainWindow(), "mysegementedcontrol");
if (segmentedControl == null) {
UIALogger.logMessage("Still could not find it");
}
....
}
EDIT: app.logElementTree(), ( "PhysicianCollectionParentView" - " " - , ):

EDIT: . "" . , UIView. .



"" , UIView:
@interface PhysicianCollectionMasterViewController ()
@property (strong, nonatomic) IBOutlet UISegmentedControl *viewSelectionControl;
@property (strong, nonatomic) IBOutlet UIView *physicianCollectionView;
@end
EDIT: - - script, , . , JavaScript, , :
var target = UIATarget.localTarget();
target.frontMostApp().mainWindow().elements()["PhysicianCollectionParentView"].tapWithOptions({tapOffset:{x:0.45, y:0.04}});
, , - , , UI Automation , . . , - , , , .