Edit this Doc Actions

Perform a chain or multiple chains of keyboard and pointer (touch, mouse, stylus) actions

Example Usage

WebElement source = (MobileElement) driver.findElementsByAccessibilityId("SomeAccessibilityID"); WebElement target = (MobileElement) driver.findElementsByAccessibilityId("SomeOtherAccessibilityID");
Actions actionBuilder = new Actions(driver); Action dragAndDropAction = actionBuilder.clickAndHold(source) .moveToElement(target, 1, 1) .release(target) .build(); dragAndDropAction.perform();
element = driver.find_element_by_accessibility_id("elId")
actions = ActionChains(driver)
actions.move_to_element(el)
actions.click(hidden_submenu)
actions.perform()

// webdriver.io example
// Example: expressing a 1-second pinch-and-zoom
// with a 500ms wait after the fingers first touch:
browser.actions([{
    "type": "pointer",
    "id": "finger1",
    "parameters": {"pointerType": "touch"},
    "actions": [
        {"type": "pointerMove", "duration": 0, "x": 100, "y": 100},
        {"type": "pointerDown", "button": 0},
        {"type": "pause", "duration": 500},
        {"type": "pointerMove", "duration": 1000, "origin": "pointer", "x": -50, "y": 0},
        {"type": "pointerUp", "button": 0}
    ]
}, {
    "type": "pointer",
    "id": "finger2",
    "parameters": {"pointerType": "touch"},
    "actions": [
        {"type": "pointerMove", "duration": 0, "x": 100, "y": 100},
        {"type": "pointerDown", "button": 0},
        {"type": "pause", "duration": 500},
        {"type": "pointerMove", "duration": 1000, "origin": "pointer", "x": 50, "y": 0},
        {"type": "pointerUp", "button": 0}
    ]
}]);

// release an action
browser.actions();



// wd example
// Not supported

# Send keys to an element
action_builder = driver.action
keyboard = action_builder.key_input
el = driver.find_element(id: "some_id")
driver.action.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys('keys').perform

// TODO

// TODO

Description

The Actions API takes a list of input sources and executes each 'tick'. A 'tick' is a slice of an action chain, so if you have two input sources, the first 'tick' is the 0-indexed action, the second 'tick' is the 1-indexed action, etc.... All of the actions per tick are executed concurrently.

Support

Appium Server

Platform Driver Platform Versions Appium Version Driver Version
iOS XCUITest 9.3+ 1.6.0+ All
UIAutomation None None None
Android Espresso ?+ 1.9.0+ All
UiAutomator2 ?+ 1.6.0+ All
UiAutomator None None None
Mac Mac ?+ 1.6.4+ All
Windows Windows 10+ 1.6.0+ All

Appium Clients

Language Support Documentation
Java All seleniumhq.github.io
Python All selenium-python.readthedocs.io
Javascript (WebdriverIO) All
Javascript (WD) All
Ruby All www.rubydoc.info
PHP All github.com
C# All github.com

HTTP API Specifications

Endpoint

POST /wd/hub/session/:sessionId/actions

URL Parameters

name description
session_id ID of the session to route the command to

JSON Parameters

name type description
actions array<array> An array of input sources
actions[$INDEX] object An object that represents an input source
actions[$INDEX].type string The type of input source. Can be 'pointer', 'key' or 'null'
actions[$INDEX].id string Unique identifier of the input device which is used for current and future actions
actions[$INDEX].parameters object (optional) Set parameters for the input source. Required for 'pointer' inputs
actions[$INDEX].parameters.pointerType string Type of pointer. Can be 'touch', 'mouse' or 'pen'
actions[$INDEX].actions array<object> A list of actions to perform on the input source
actions[$INDEX].actions array<object> A list of actions to perform on the input source
actions[$INDEX].actions[$INDEX] object The action to perform on the input source
actions[$INDEX].actions[$INDEX].type string The type of action. For any input source it can be 'pause'. For 'pointer' input source 'pointerMove', 'pointerUp' or 'pointerDown'. For 'key' it can be 'keyDown' or 'keyUp'
actions[$INDEX].actions[$INDEX].value string For a 'keyUp' or 'keyDown' action thevalue to send to the keyboard. Should be a one-character string ("s", "\uE009")
actions[$INDEX].actions[$INDEX].duration number How long to perform the action in 'ms'. Only applicable to 'pause' and 'pointerMove'.
actions[$INDEX].actions[$INDEX].origin string|object For 'pointerMove', this tells the input source what x,y are relative to. Can be 'viewport', 'pointer' or {'element-6066-11e4-a52e-4f735466cecf': ''}
actions[$INDEX].actions[$INDEX].x number X coordinate of pointer move event
actions[$INDEX].actions[$INDEX].y number Y coordinate of pointer move event

Response

null

See Also