Scroll down with Java using Selenium Web Driver (Appium)

I’m trying to scroll down in an APK page with Java. I’m using Appium and Selenium.

I tried:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript(“window.scrollBy(0,250)”, “”);

And driver.scrollToExact(); commands but they are not supported by “WebDriver”.

How can I do this?

Can you try with moveToElement

WebElement element = driver.findElement(By.linkText(“Product Category”));

    Actions action = new Actions(driver);

    action.moveToElement(element).build().perform();

Thanks for help but it couldnt find the element
The element which i search for is not on the screen so i need to scroll, do you think this problem is result of that or any other problem? Is moveToElement function provide this?

Here you can see the below code snippet it will take a while loop and search for that element if its found it will be break loop, else it will swipe and will try to find that element. its working fine for me

if(!workFlowDataMap.get(“CUSTOMERNAME”).equalsIgnoreCase(“SKIP”)){
customerNames=workFlowDataMap.get(“CUSTOMERNAME”).split(",");
for(int i=0; i<customerNames.length; i++){
while(true)
{
if(findElement(customerNames[i]))
{
break;
}
else
{
mdriver.swipe(33, 1080, 767, 313, 1000);
}

		      }
			MobileElement element=mdriver.findElement(By.name(customerNames[i]));
			TouchAction action = new TouchAction(mdriver);
			action.longPress(element).release().perform();
		}
		
	}

My code is very similar to above. Until you find what you’re looking for, keep swiping!

public void selectCustomer(String customer) {
    Dimension size = driver.manage().window().getSize();
    int startX = size.width / 2;
    int startY = (int) (size.height * .8);
    int endY = (int) (size.height * .2);

    if (platform.equalsIgnoreCase("ios")) {
        while(!driver.findElementById(customer).isDisplayed()) {
            driver.swipe(startX, startY, startX, endY, 100);
        }
        driver.findElementById(customer).click();
    }
}

if u have a scrollable element you can use Android UISelector - UiScrollable object. It belongs to the UIAutomator object.
To find your element please use :

WebElement el = driver.findElement(MobileBy.
AndroidUIAutomator("new UiScrollable(new UiSelector()).
scrollIntoView("+ “new UiSelector().text(”"+element+""));"));

When “new UiSelector().text(”"+element+""));" can be located by other locators as id , index and etc…
also please refer to the next example link :


for more info about UISelector in the Android Api please refer to: https://developer.android.com/reference/android/support/test/uiautomator/UiSelector.html