Uiautomator - Cannot get ListView to scroll when I check text in each list item. it just fails when I click the last item on the screen

I am trying to check the text in each element of a list in my ListView and scroll down one at a time so that I can check each of them ... but for some reason I cannot make it continue to scroll through the list that checks each element. Someone had luck automating such an action. Here is the closest I can come to. Please let me know if this is not enough.

UiScrollable scrollableList = new UiScrollable(new UiSelector() .resourceId("com.example.app:id/listView") .className(android.widget.ListView.class.getName()) .index(3)); for ( i = 0; i < 100; i++ ) { UiObject listItem = scrollableList.getChildByText(new UiSelector() .className("android.widget.RelativeLayout") .instance(i), "Text Title"); UiObject textBody = listItem.getFromParent(new UiSelector() .resourceId("com.example.app:id/textBody")); System.out.println("Validating: " + textBody.getText()); 

Currently there are only 5 listItems on the screen, so it fails when it tries to get to number 6, which it cannot, because:

a. he will not try to scroll forward to get the next one on the list
b. , even if he scrolled forward to get the next one on the list, the instance value will decrease to 5, instead of increasing to 6.

I tried this without the .instance () method, but in this case, it again and again iterates over the first item in the list, without going to paragraph 2,3,4 ect.

If anyone ran into this problem, I would love the feedback.

+6
source share
2 answers

In my case, I just want to get all the values ​​from this page. A limitation of Android is that you can only work with objects that are currently visible on the screen. Check this link for Ui Automator with restrictions using Mobile Automation - http://www.automationtestinghub.com/more-about-ui-automator-viewer/ In addition, I also tried this example - http: //www.qaautomated. com / 2016/02 / how-to-scroll-in-appium.html . I also tried this solution, but it was not useful for me, but you can try this - http://www.automationtestinghub.com/uiselector-android/ . I used below lines of code that solves my problem.

 // to print value of visible objects on screen. List<MobileElement> allTitleElements = ((AndroidDriver<MobileElement>)driver).findElementsByAndroidUIAutomator("new UiSelector().resourceId(\"com.experient.swap:id/editText\")"); System.out.println("Element Count - " + allTitleElements.size()); for(MobileElement element : allTitleElements) { System.out.println("Text - " + element.getText()); } // to click on last element of screen(country in my case) to scroll down page to last object MobileElement abc = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(" +"new UiSelector().text(\"Country\"));")); abc.click(); 
0
source

I implemented the same functionality in python without using java. I am writing the logic below, see if it helps you.

 while(i<100): self.d.press('down') print self.d(resourceID='android:id/text1').text 

This loop scrolls up to 100 items and returns each item in the drop-down menu.

-1
source

Source: https://habr.com/ru/post/1212504/


All Articles