How do I automate scrolling in a native Android application? For example, on a 'terms and conditions' page. I am using Appium with selenium webdriver.
2 Answers
The snippet below is not for any particular mobile screen size. It is fetching the actual screen size each time.
public void scroller() throws IOException
{
Dimension dimensions = ad.manage().window().getSize();
System.out.println("Size of Window= " +dimensions);
int scrollStart = (int) (dimensions.getHeight() * 0.5);
System.out.println("Size of scrollStart= " +scrollStart);
int scrollEnd = (int) (dimensions.getHeight() * 0.2);
System.out.println("Size of cscrollEnd= " + scrollEnd);
driver.swipe(0,scrollStart,0,scrollEnd,1000);
System.out.println("Screen Swiped " );
}
Using python-client of appium:
def _find_by_scroll(self, item_name):
item = self.driver.find_element_by_android_uiautomator(
'new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className("android.widget.TextView"), "'
+ item_name + '")')
item.click()