Files
appium/docs/touch-actions.md
Manikandan M G 2ba82d1902 Code snippet for long press in Android Touchevent (Java and Python)
Updating python script for longclick  touchevent in android.
2013-09-20 11:31:57 +05:30

1.0 KiB

Touch Actions

WebDriver provides an API to send some kinds of touch gestures to the devices, for example, to long press an element you can do:

For iOS Application:

final WebElement imageView = searchResults.findElement(By.tagName("ImageView"));
new TouchActions(driver).longPress(imageView).perform();

For Android Application:

Java:

WebElement element = wd.findElement(By.name("API Demo"));
JavascriptExecutor js = (JavascriptExecutor) wd;
HashMap<String, String> tapObject = new HashMap<String, String>();
tapObject.put("element", ((RemoteWebElement) element).getId());
js.executeScript("mobile: longClick", tapObject);

Python:

element = wd.find_element_by_xpath("your_element_xpath")
wd.execute_script("mobile: longClick",{ "touchCount": 1, "x": 0, "y": 300, "element":element.id })

Currently Appium support some of the gestures in the Touch Actions API:

  • flick
  • long press
  • single tap

Some other gestures are supported through the "Alternative access method" explained in Automating mobile gestures