Finds the View with the specified viewId. @type viewId: str @param viewId: the ID of the view to find @type root: str @type root: View @param root: the root node of the tree where the View will be searched @type: viewFilter: function
(self, viewId, root="ROOT", viewFilter=None)
| 3739 | return self.windows |
| 3740 | |
| 3741 | def findViewById(self, viewId, root="ROOT", viewFilter=None): |
| 3742 | """ |
| 3743 | Finds the View with the specified viewId. |
| 3744 | |
| 3745 | @type viewId: str |
| 3746 | @param viewId: the ID of the view to find |
| 3747 | @type root: str |
| 3748 | @type root: View |
| 3749 | @param root: the root node of the tree where the View will be searched |
| 3750 | @type: viewFilter: function |
| 3751 | @param viewFilter: a function that will be invoked providing the candidate View as a parameter |
| 3752 | and depending on the return value (C{True} or C{False}) the View will be |
| 3753 | selected and returned as the result of C{findViewById()} or ignored. |
| 3754 | This can be C{None} and no extra filtering is applied. |
| 3755 | |
| 3756 | @return: the C{View} found or C{None} |
| 3757 | """ |
| 3758 | |
| 3759 | if self.uiAutomatorHelper: |
| 3760 | # If we are using uiAutomatorHelper let's find object directly without traversing the tree |
| 3761 | return self.uiAutomatorHelper.ui_device.find_object(by_selector=f'res@{viewId}') |
| 3762 | |
| 3763 | if not root: |
| 3764 | return None |
| 3765 | |
| 3766 | if root == "ROOT": |
| 3767 | return self.findViewById(viewId, self.root, viewFilter) |
| 3768 | |
| 3769 | try: |
| 3770 | rootId = root.getId() |
| 3771 | except AttributeError as ex: |
| 3772 | try: |
| 3773 | rootId = root.resource_id |
| 3774 | except AttributeError as ex: |
| 3775 | rootId = root.id |
| 3776 | |
| 3777 | if rootId == viewId: |
| 3778 | if viewFilter: |
| 3779 | if viewFilter(root): |
| 3780 | return root |
| 3781 | else: |
| 3782 | return root |
| 3783 | |
| 3784 | if re.match('^id/no_id', viewId) or re.match('^id/.+/.+', viewId): |
| 3785 | try: |
| 3786 | unique_id = root.getUniqueId() |
| 3787 | except AttributeError as ex: |
| 3788 | try: |
| 3789 | unique_id = root.unique_id |
| 3790 | except AttributeError as ex: |
| 3791 | unique_id = -1 |
| 3792 | |
| 3793 | if unique_id == viewId: |
| 3794 | if viewFilter: |
| 3795 | if viewFilter(root): |
| 3796 | return root; |
| 3797 | else: |
| 3798 | return root |