TouchActions action = new TouchActions(driver);
action.scroll(element, 10, 100);
action.perform();
But in first line I’m getting an exception " java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen"
My environment is: java, jdk 1.8.0_65, appium 1.6.1
This is a guess but you might have a mismatch between your versions of appium, java-client, and selenium-java…
Try upgrading your appium version to 1.8 and then upgrade the corresponding libraries…
I have:
appium = 1.8
io.appium.java-client = 6.0.0
org.seleniumhq.selenium.selenium-java = 3.9.1
JDK = 1.8
(This was somewhat of java 6 language specific thing)
After multiple tries and pages, here is what I found as a working solution:
public void scrollDown() {
//The viewing size of the device
Dimension size = driver.manage().window().getSize();
//x position set to mid-screen horizontally
int width = size.width / 2;
//Starting y location set to 80% of the height (near bottom)
int startPoint = (int) (size.getHeight() * 0.80);
//Ending y location set to 20% of the height (near top)
int endPoint = (int) (size.getHeight() * 0.20);
new TouchAction(driver).press(PointOption.point(width, startPoint)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000))).moveTo(PointOption.point(width, endPoint)).release().perform();
}
My driver is a public property on top of the class: