# # Automation of Mobile gestures
Although the selenium Webdriver specification supports several ways to interact with a cell phone, its parameters do not simply map to the automation functions used by the underlying device (like the uiautomation on iOS). To this end, Appium defines a new touch operation/Multitouch API in the latest version of the specification
([Https://dvcs.w3.org/hg/webdriver/raw-file/tip/webdriver-spec.html#multiactions-1] (https://dvcs.w3.org/hg/ WEBDRIVER/RAW-FILE/TIP/WEBDRIVER-SPEC.HTML#MULTIACTIONS-1)).
Note that this is different from the touch Operation API used in earlier versions of the original JSON wire Protocol.
These APIs enable you to use multiple drivers to create arbitrary gestures. Refer to the Appium client documentation for the corresponding language to find examples of using these APIs.
Overview of # # # Touch Operations/Multitouch API
# # # Touch operation (touchaction)
The *touchaction* object contains a series of events.
In all Appium client libraries, touch objects Create and give a series of events.
The available events in the specification are:
* Short push (press)
* Released (release)
* Move to (MoveTo)
* Click (TAP)
* Waiting (Wait)
* Long Press (longpress)
* Cancellation (Cancel)
* Execution (perform)
Here is an example of creating an action with pseudo-code:
"' Center
Touchaction (). Press (EL0). MoveTo (EL1). Release ()
```
The above simulated user presses an element, slides his finger to another position, and then releases its finger from the screen.
These events are executed sequentially by Appium. You can add a ' wait ' event to control the time of the corresponding gesture.
The Appium client library has different ways to implement the above example, such as: you can pass a coordinate value or an element to the ' MoveTo ' event. Passing coordinates and elements at the same time corresponds to the coordinates and elements, but this is not absolute.
Call the ' perform ' event to send the entire sequence of events to Appium, allowing the touch gesture to run on the device.
The Appium client also allows people to perform touch operations directly from the driver object, rather than invoking the ' perform ' event of the touch manipulation object.
In pseudo-code, the following two are equivalent:
"' Center
Touchaction (). Tap (EL). Perform ()
Driver.perform (Touchaction (). Tap (EL))
```
# # # Multi-Touch (MultiTouch)
The *multitouch* object is a collection of touch operations.
Multitouch gestures only have two methods, add (' Add ') and execute (' perform ').
' Add ' is used to add different touch actions to a multi-touch.
When ' perform ' is called, all touch events that are added to the multi-touch will be sent to Appium and executed as if they were happening at the same time. Appium executes the first event in touch events, then the second one, and so on.
Sample code with two finger clicks:
"' Center
Action0 = Touchaction (). Tap (EL)
Action1 = Touchaction (). Tap (EL)
Multiaction (). Add (Action0). Add (Action1). Perform ()
```
# # # Defects and Solutions
Unfortunately there is a flaw in iOS 7.x simulator, Scrollviews does not recognize gestures created by uiautomation (Appium using UIAutomation on iOS). In order to implement this function, we have provided new functions, ' scroll ', which in most cases allows you to achieve the same functions as ScrollView!
* * Scrolling * *
To use this special feature, we rewrote the ' execute ' in driver and
' Executescript ' method. You can use scrolling by prefixing the command with ' Mobile: '.
See the following example:
* **wd.js:**
"' JavaScript
Javascript
Slide the View down
Driver.execute ("Mobile:scroll", [{direction: ' down '}])
Continue testing
```
* **java:**
"' Java
Java
Javascriptexecutor js = (javascriptexecutor) driver;
hashmap<string, string> scrollobject = new hashmap<string, string> ();
Scrollobject.put ("direction", "down");
Scrollobject.put ("Element", (remotewebelement) Element). GetId ());
Js.executescript ("Mobile:scroll", scrollobject);
```
* * Automatic Slider Automation * *
**ios**
* **java**
"' Java
Java
Slide values are represented as strings using numbers between 0 and 1
For example, "0.1" stands for 10%, "1.0" for 100%
Webelement slider = driver.findelement (By.xpath ("//window[1]/slider[1]");
Slider.sendkeys ("0.1");
```
**android**
The best way to interact with the sliders on Android is with touch operation (touchactions).
Automation of mobile gestures