iOS UIAutomation : Accessing custom subviews added on a UIScrollView in automation script
Asked Answered
F

1

6

I am very new to the iOS UIAutomation, here is the problem I am facing

I have a view hierarchy as below and want to access CustomView2 elements in the automation sctipt

UIWindow > UIScrollView > CustomView1 (Multiple) > CustomView2 (Multiple)

The scrollview has subviews of type CustomView1 and CustomView1 in turn has subviews of type CustomView2.

I have assigned the accessibility information to all of the views in hierarchy, but I am not able to access the CustomView2 elements in my automation script.

When I do a logElementTree() on UIScrollView, all I get is the instances of CustomView2, CustomView2 is not even in the tree structure of UIWindow.

Please suggest if is there anything missing or anything going wrong.

Here is the code I am using

var mainWindow = application.mainWindow();
var scrollView = mainWindow.scrollViews()[0];
var custom1 = scrollView.elements().withName("CustomView1");

for(var index=0; index<custom1.length; index++){
    currentIndustry.tap();
    custom1[index].logElementTree();
    var custom2 = custom1[index].elements().withName("CustomView2");
    UIALogger.logPass("Custom2 Length : " + custom2.length);
}

The tree printed by custom1[index].logElementTree(); does not contain instances of CustomView2

P.S. I need to access both CustomView1 and CustomView2 elements

Feria answered 20/10, 2011 at 9:51 Comment(2)
I had a similar question. Try my question and answer: #6752066Stotinka
Thank you @JackyBoy for the reference. That did solve the issue partially, I need to access both CustomView1 and CustomView2, by removing the accessibility of CustomView1 apparently I loose access to CustomView1.Feria
O
5

This may help you if you haven't found your answer already:

UIAutomation Nested Accessibilty Elements Disappear from Hierarchy

In your CustomView1 class implement the following:

- (BOOL)isAccessibilityElement
{
    return NO;
}

This will make your CustomView2 elements visible when you logElementTree().

If CustomView2 contains accessible elements and is basically a container view as well, then implement the above in that class as well, and it's child views will become accessible.

Oversweet answered 18/1, 2012 at 17:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.