How do I scroll down to click an element in Android using appium and Java?
I wonder how to scroll down to click an element in Android using appium and Java?
I have a list of elements in "Android. Support. V7. Widget. Recyclerview" Since it has more than 10 elements, we need to slide the screen to see the following elements Each element has the same ID, which is "com. Osanda. Exampleapp / textviewtitle" But their words are different, such as "apple", "orange", "graphics"
I just need to scroll and click the text of the relevant element ("apple", "graphics"...)
I've followed many tutorials, but I can't finish them correctly I managed to scroll down the screen However, when the element is in the middle of the scroll, it will not work
When I list element names, it shows only visible elements, not all elements
List<WebElement> elements = androidDriver.findElementByClassName("android.support.v7.widget.RecyclerView").findElements(By.id("com.osanda.exampleapp:id/textViewTitle")); for(WebElement element : elements) { System.out.println(element.getText()); }
thank you.
Solution
It works for me
public void scrollAndClick(String visibleText) { androidDriver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+visibleText+"\").instance(0))").click(); } }