Search code examples
appium

How to scroll to a element which is not visible in appium?


In the previous version of Appium, I can use scroll functions to scroll to the particular element which is not visible on the screen.

My requirement is I have a Layout, in which many elements are there and that layout is scrollable. The element which I want to click is not visible on the screen and I have to scroll to a particular element and click that?

Can someone help me out on this issue how to scroll to the particular element?


Solution

  • In latest version of appium to scroll on the screen or to scroll the tables or to implement drag and drop functionalites we have to use TouchAction.

    If we want to scroll in a scrollable layout first we have to get the bounds of that layout and give the coordinates in side that bounds.

    Consider the below line of code.

    new TouchAction(driver).press(300,200).moveTo(300,100).release().perform();
    

    In this line of code we will perform the scroll down by 100 points.

    .press(300,200) // Start at 300,200
    .moveTo(0,100) // Increase Y by 300, ending up at 300,100
    

    You have to pass the coordinates based on your requirements.

    Find the details in below link:

    https://appium.io/docs/en/writing-running-appium/touch-actions/