Appium iOS: swipe element using JavascriptExecuter

Last updated on:

Sometimes you need to perform JavaScript swipe on mobile device, I'm using following code to perform swipe on iOS application I'm currently testing:

WebElement element = (WebElement) ((JavascriptExecutor)driver).executeScript("mobile: swipe", new HashMap<String, Double>() {{ put("touchCount", 1.0); put("startX", 283.0); put("startY", 362.0); put("endX", 34.0); put("endY", 358.0); put("duration", 0.5); }});

While running script execution I have faced an issue, which was looking like that:

java.lang.ClassCastException: java.lang.String cannot be cast to org.openqa.selenium.WebElement

The code bellow solved the problem:

JavascriptExecutor js = (JavascriptExecutor) driver;
	 js.executeScript("mobile: swipe", new HashMap<String, Double>() {{ put("touchCount", 1.0); put("startX", 281.0); put("startY", 276.0); put("endX", 67.0); put("endY", 276.0); put("duration", 0.5); }});
View Comments

Leave a Comment

Use markdown or basic HTML and be nice.