Android automated testing experience sharing in-depth UiScrollable

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.