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");
Point source = dragMe.getCenter(); Point target = driver.findElementByAccessibilityId("dropzone").getCenter(); PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); Sequence dragNDrop = new Sequence(finger, 1); dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), source.x, source.y)); dragNDrop.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(700), PointerInput.Origin.viewport(),target.x, target.y)); dragNDrop.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); driver.perform(Arrays.asList(dragNDrop));
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
// Performs a 'pinch-and-zoom'
var actions = new wd.W3CActions(driver);
var touchInput = actions.addTouchInput();
touchInput.pointerMove({duration: 0, x: 100, y: 100});
touchInput.pointerDown({button: 0});
touchInput.pause({duration: 500});
touchInput.pointerMove({duration: 1000, origin: 'pointer', x: -50, y: 100});
touchInput.pointerUp({button: 0});
var secondTouchInput = actions.addTouchInput();
secondTouchInput.pointerMove({duration: 0, x: 200, y: 200});
secondTouchInput.pointerDown({button: 0});
secondTouchInput.pause({duration: 300});
secondTouchInput.pointerMove({duration: 1000, origin: 'pointer', x: 50, y: 100});
secondTouchInput.pointerUp({button: 0});
await actions.perform();

// Releases any previously run actions (e.g.: if a key is 'down' because of /actions, releases it using key up)
await driver.releaseW3CActions();

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

# Build multiple action chains
# Example: expressing a 1-second pinch-and-zoom
# with a 500ms wait after the fingers first touch:
f1 = driver.action.add_pointer_input(:touch, 'finger1')
f1.create_pointer_move(duration: 1, x: 200, y: 500, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
f1.create_pointer_down(:left)
f1.create_pause(0.5)
f1.create_pointer_move(duration: 1, x: 200, y: 200, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
f1.create_pointer_up(:left)

f2 = driver.action.add_pointer_input(:touch, 'finger2')
f2.create_pointer_move(duration: 1, x: 200, y: 500, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
f2.create_pointer_down(:left)
f2.create_pause(0.5)
f2.create_pointer_move(duration: 1, x: 200, y: 800, origin: ::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT)
f2.create_pointer_up(:left)

driver.perform_actions [f1, f2]

// 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