Reputation: 361
im trying to scroll in a native android app by using the method below
Dimension size = driver.manage().window().getSize();
int starty = (int) (size.height * 0.80);
int endy = (int) (size.height * 0.20);
int startx = size.width / 2;
driver.swipe(startx, starty, startx, endy, 3000);
Thread.sleep(2000);
but at driver.swipe
it gives me an error that says
The method swipe(int, int, int, int, int) is undefined for the type AndroidDriver
can anyone help me fix this? i have been searching forever trying to find a solution but i have had no luck.
Upvotes: 4
Views: 6914
Reputation: 7563
You can use TouchAction
instead .swipe
:
TouchAction action = new TouchAction(driver);
action.press(x, y).moveTo(x, y).release().perform();
You can also implement x y
with PointOption
, like this:
.press(new PointOption().withCoordinates(x, y))
Or
.press(PointOption.point(x, y))
Following import:
import io.appium.java_client.TouchAction;
Upvotes: 3
Reputation: 246
Try this technique instead of appium methods.
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<>();
scrollObject.put("direction", "down");
js.executeScript("mobile: swipe", scrollObject);
Upvotes: 0