def accessibilityGrepHierarchy()

in commands/FBAccessibilityCommands.py [0:0]


    def accessibilityGrepHierarchy(self, view, needle):
        a11yLabel = accessibilityLabel(view)
        # if we don't have any accessibility string - we should have some children
        if int(a11yLabel.GetValue(), 16) == 0:
            # We call private method that gives back all visible accessibility children
            # for view iOS 10 and higher
            if fb.evaluateBooleanExpression(
                "[UIView respondsToSelector:@selector(_accessibilityElementsAndContainersDescendingFromViews:options:sorted:)]"
            ):
                accessibilityElements = fb.evaluateObjectExpression(
                    "[UIView _accessibilityElementsAndContainersDescendingFromViews:@[(id)%s] options:0 sorted:NO]"
                    % view
                )
            else:
                accessibilityElements = fb.evaluateObjectExpression(
                    "[[[UIApplication sharedApplication] keyWindow] _accessibilityElementsInContainer:0 topLevel:%s includeKB:0]"
                    % view
                )
            accessibilityElementsCount = fb.evaluateIntegerExpression(
                "[%s count]" % accessibilityElements
            )
            for index in range(0, accessibilityElementsCount):
                subview = fb.evaluateObjectExpression(
                    "[%s objectAtIndex:%i]" % (accessibilityElements, index)
                )
                self.accessibilityGrepHierarchy(subview, needle)
        elif re.match(
            r".*" + needle + ".*", a11yLabel.GetObjectDescription(), re.IGNORECASE
        ):
            classDesc = objHelpers.className(view)
            print(
                "({} {}) {}".format(classDesc, view, a11yLabel.GetObjectDescription())
            )

            # First element that is found is copied to clipboard
            if not self.foundElement:
                self.foundElement = True
                cmd = 'echo %s | tr -d "\n" | pbcopy' % view
                os.system(cmd)