How to scroll/swipe in Chrome Browser with TouchActions

Hi @jlipps, @willosser, @bhaskar, @Appium_Master

I’m Trying to automate my application in Android Chrome browser… I need click on an element below the screen. I’ve tried Touch Actions(press, release, moveTo, Tap) to scroll. But didn’t worked. My questions

  1. Didn’t appium automatically scroll to the element like selenium
  2. if not, how can i scroll to particular element

I’ve tried TouchActions using coordinates but no avail

below is my code

@Test
public void webView() throws Exception{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, BrowserType.CHROME);
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,“Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,“ZY22232RXB”);
capabilities.setCapability(“appPackage”,“com.android.chrome”);
capabilities.setCapability(“appActivity”,“com.google.android.apps.chrome.Main”);
mobileDriver= new AndroidDriver(new URL(“http://127.0.0.1:4445/wd/hub”), capabilities);
mobileDriver.get(url);
TouchAction action = new TouchAction(mobileDriver);
WebElement el = mobileDriver.findElement(By.xpath("//h4"));
WebElement e2 = mobileDriver.findElement(By.xpath("//div[text()=‘View All’]"));
int x = el.getLocation().getX();
int y = el.getLocation().getY();

    int x1 = e2.getLocation().getX();
    int y1 = e2.getLocation().getY();

    mobileDriver.context("NATIVE_APP");
    action.press(x1,y1).moveTo(x,y).release().perform().wait(500);
    el.click();
    mobileDriver.context("CHROMIUM");
}

it is not pressing the intended button and move to is not happening . Please help

Appium 1.6.4
Java-client 1.5.0
Android API-23
Chrome version: 61.0
ChromeDriver 2.25

Selenium can “see” all elements, but Appium on Android cannot. I suspect you want to use scrollTo

Thanks @willosser, but with latest appium-Java-client(1.5.0) , scrollTo, swipe are removed

1 Like

I am facing similar problem only on android emulator.
can’t find any scroll/swipe working method on the latest version.

hope we get an answer :slight_smile:

Because scrollTo never worked well in the ruby client we ended up creating our own scrollTo method. Assuming you can use Touch or something else equivalent, you can build it like this:

Get dimensions of scrollable window/element
while object is not visible
swipe from (mid_x, bottom_y * .8) to (mid_x, top_y * 1.2)
end

You can search for text on the screen, or resource-id, or whatever.