UiScrollable is a UiCollection and provides support for searching for items in a scrollable user interface (UI) elements. This class can be used with horizontally or vertically scrollable controls.
UiScrollable is a UiCollection (this is not understood yet). We can use it to slide pages (either horizontally or up or down) to find the desired control (item ).
Example 1:The following scrollClickObject method uses UiScrollable to automatically select the control we want to click.
Copy codeThe Code is as follows: public void scrollClickObject (String targetClassName, String targetName) throws UiObjectNotFoundException {
UiScrollable collectionObject = new UiScrollable (new UiSelector (). scrollable (true ));
If (collectionObject. exists ()){
UiObject scrollableObject = collectionObject. getChildByText (new UiSelector (). className (targetClassName), targetName );
ScrollableObject. clickAndWaitForNewWindow ();
} Else {
UiObject targetObject = new UiObject (new UiSelector (). className (targetClassName). text (targetName ));
TargetObject. clickAndWaitForNewWindow ();
}
}
First, define a UiScrollable object. The only condition for recognizing this object is that there is a slide control on the screen. (There is a problem here, that is, if there are two slip controls on the screen at the same time, an error will be reported)
Then we can determine whether the slide object exists.
• If yes, use the getChildByText method to obtain the control we want to click and then click it.
• If it does not exist, the page cannot be moved, that is, all controls are displayed on the interface. Then we can directly use UiObject to get the control and operate on it.