How to understand uiautomator inside the child, Child_by_text, sibling, we use the Android native Uiautomatorviewer crawl control to understand
With a detailed explanation (the left and right sides are circled by different colors, indicating the attribution of these controls), such as the red circle part as a parent class, the green circle and the yellow circle are its subclasses (called Child), and the green and yellow circles belong to the same level relationship, Can be understood as brotherly relationships (called sibling)
For example, to click on the "Navigation bar Hide" switch to open or close, the code is:
1 ' Android.widget.LinearLayout '). Child_by_text ('Adaptive brightness'android.widget.RelativeLayout ' ' Android:id/switch_widget '). Click ()
Follow the code from left to right execution, first find the classname of the parent class, you will find that there are many such controls in the interface interface, there is no way to make a unique identification, and then look for the child class in the parent class classname precise positioning menu options, You will find that subclasses of other parent classes are all the same, there is no way to make a unique determination, and then add a caption in the subclass (this is unique), so this will need to use the. Child_by_text method to locate the option to switch the option after it is found. And because the subclass of the Child_by_text is a sibling to the beginning of the control to be clicked, the. Sibling method allows for further precise positioning.
A, ClassName = ' android.widget.LinearLayout ' : This is the parent class
B, className = ' android.widget.RelativeLayout ': This is a subclass of step a, but it's a sibling relationship with step d.
C, ' Adaptive brightness ' : This is a subclass of step b
D, resourceId = ' Android:id/switch_widget ' This is a sub-class of step a, but with the B-step sibling relationship
Summary: The code using the scene is in an Android interface (such as setting the interface), there are several options to switch operation, you need to use this method, or you can not operate other switch options.
The following is a source code that operates on two switches in the Setup interface:
1#-*-coding:utf-8-*-2 " "3 Created on July 27, 20184 5 @author: any6 " "7 fromUiautomator Import Device asD8 whileTrue:9 ifD (className ='Android.widget.LinearLayout'). Child_by_text ('Navigation Bar Hide', ClassName ='Android.widget.RelativeLayout'). Sibling (ResourceId ='Android:id/switch_widget'):TenD (className ='Android.widget.LinearLayout'). Child_by_text ('Navigation Bar Hide', ClassName ='Android.widget.RelativeLayout'). Sibling (ResourceId ='Android:id/switch_widget'). Click () One Else: AD (className ='Android.widget.LinearLayout'). Child_by_text ('Navigation Bar Hide', ClassName ='Android.widget.RelativeLayout'). Sibling (ResourceId ='Android:id/switch_widget'). Click () - ifD (className ='Android.widget.LinearLayout'). Child_by_text ('Adaptive Brightness', ClassName ='Android.widget.RelativeLayout'). Sibling (ResourceId ='Android:id/switch_widget'): -D (className ='Android.widget.LinearLayout'). Child_by_text ('Adaptive Brightness', ClassName ='Android.widget.RelativeLayout'). Sibling (ClassName ='Android.widget.Switch'). Click ()
[Python] How to understand uiautomator inside the child, Child_by_text, sibling, and usage scenarios