Below you can find a sample Java code that will use the Perfecto Swipe (FR) command to swipe/scroll down to an element.

In this example the code will use an Appium driver, an xPath locator and will swipe/scroll down up to 5 times to find the element.

You may change the driver, locator, retry counter and coordinates to fit your needs.

public static void scrollDowntoXPath(String xPath, AppiumDriver driver) {
	boolean flag=true;
	int count=1;
    while(flag){
    	try {
	    	driver.findElement(By.xpath(xPath));
	    	flag=false;
	    	break;
    	}
    	catch(Exception NoSuchElementException) {
    		count=count+1;
	    	Map<String, Object> params = new HashMap<>();
	    	params.put("start","40%,90%");
	    	params.put("end","40%,20%");
	    	params.put("duration","2");
	    	Object res= driver.executeScript("mobile:touch:swipe",params);
    	if(count==5)
    	{
    		break;
    	}
    	}
    }
}
<iframe width="560" height="315" src="https://www.youtube.com/embed/1tO6xF2FM_8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>


Related articles

Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.

Related issues