Mobile Gestures

Selendroid is implementing the Advanced User Interactions API. This is a new, more comprehensive API for describing actions a user can perform on an app. This includes actions such as drag and drop or clicking multiple elements while holding down the Control key.

Supported Interactions

  • doubleTap(WebElement onElement)
  • down(int x, int y)
  • flick(int xSpeed, int ySpeed)
  • flick(WebElement onElement, int xOffset, int yOffset, int speed)
  • longPress(WebElement onElement)
  • move(int x, int y)
  • singleTap(WebElement onElement)
  • up(int x, int y)

Examples

How to swipe from right to left

Ruby:

#Please include the touch screen:
#include Selenium::WebDriver::DriverExtensions::HasTouchScreen
pages = driver.find_element(:id,'vp_pages')
driver.touch.flick(pages,-100,0,:normal).perform

Python:

#import
from selenium import webdriver
from selenium.webdriver.common.touch_actions import TouchActions
# Gestures code
pages = driver.find_element_by_id("vp_pages")
touch_actions = TouchActions(driver)              
touch_actions.flick_element(pages,0,-100,0).perform()

Java:

#Please import: org.openqa.selenium.interactions.touch.TouchActions
WebElement pages = driver.findElement(By.id("vp_pages"));
TouchActions flick = new TouchActions(driver).flick(pages, -100, 0, 0);
flick.perform();

Multi Touch Support

The multi touch support is currently only in the Selendroid Java Client bindings available.

Single Finger Example:

TouchAction ta = new TouchActionBuilder().pointerDown().
pointerMove(x, y).pointerUp().build(); 
ta.perform(driver);

Multi Finger Example (these will be executed in parallel):

TouchAction finger1 = new TouchActionBuilder().pointerDown().pause(100).
  pointerMove(x, y).pointerUp().build(); 
TouchAction finger2 = new   TouchActionBuilder().pointerDown().pause(100).
  pointerMove(x, y).pointerUp().build(); 
MultiTouchAction multiAction = new MultiTouchAction(finger1, finger2); 
multiAction.perform(driver);