Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Last updated: Jan 23, 2019 12:53


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.

Java Code Example
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;
    	}
    	}
    }
}

  • No labels