1.UiObejct. getFromParent () usage: Find the desired sub-object from the parent object of the current object. The sub-object and the current object should be at the same level.
As shown in: Max inactivity before lock is a known condition, and 4 minutes is what I want to obtain dynamically. What should we do?
Let's take a look at the structure: TableLayout (curent index is 2)-TableRow (has several indexes)-TextView (has 2 indexes ).
1.First, obtain the object whose TableLayout index is 2.
2.Traverse the TableRow in TableLayout and obtain the text of TextView (0) in TableRow (I ).
3.When the text content of TextView (1) is "Max inactivity before lock", you can determine the TableRow we want. (In fact, it is to find the corresponding index)
4.Then we use the getFromParent () method of the current object to find the text of TextView (1), so that we can get the desired value.
Copy codeThe Code is as follows: // The following two steps are used to obtain the number of TableRow under TableLayout.
UiObject allPasswordPolicies = new UiObject (new UiSelector (). className ("android. widget. TableLayout"). index (2 ));
Int pwdcount = allPasswordPolicies. getChildCount ();
// Traverse each TableRow
For (int I = 0; I <pwdcount; I ++ ){
UiObject passcodePolicyName = allPasswordPolicies. getChild (new UiSelector (). className ("android. widget. tableRow "). index (I ). childSelector (new UiSelector (). className ("android. widget. textView "). index (0 )));
// Find the object whose TextView value is 0 in TableRow is equal to "Max inactivity before lock"
If (passcodePolicyName. getText (). contains ("Max inactivity before lock ")){
// Use the getFromParent () and getText () methods to obtain the text value of the object whose index is 1 at the same level as the current object. PasscodePolicyName. getFromParent is equivalent to TableRow (1) object.
String actualValue = passcodePolicyName. getFromParent (new UiSelector (). className ("android. widget. TextView"). index (1). getText ();
If (actualValue. equals (expectedValue )){
System. out. println (policyName + "check: Pass .");
} Else {
System. out. println (policyName + "check: Failed .");
}
}
}