dam1ne
dam1ne

Reputation: 361

How to scroll using coordinates with appium

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

Answers (2)

frianH
frianH

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:

  1. .press(new PointOption().withCoordinates(x, y))

    Or

  2. .press(PointOption.point(x, y))

Following import:

import io.appium.java_client.TouchAction;

TouchAction

PointOption

Upvotes: 3

Sammar Ahmad
Sammar Ahmad

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

Related Questions