Execute Mobile Command
Execute a native mobile command
Example Usage
// Java
driver.executeScript("mobile: scroll", ImmutableMap.of("direction", "down"));
# Python
self.driver.execute_script("mobile: scroll", {'direction': 'down'})
// Javascript
// webdriver.io example
var result = browser.execute('mobile: scroll', {direction: 'down'})
[//]: # (DO NOT EDIT THIS FILE! This is an auto-generated file. Editing for this document happens in /commands-yml/commands/mobile-command.yml)
// wd example
await driver.execute('mobile: scroll', {direction: 'down'});
# Ruby
# ruby_lib example
execute_script("mobile: scroll", { "direction" => "down"})
[//]: # (DO NOT EDIT THIS FILE! This is an auto-generated file. Editing for this document happens in /commands-yml/commands/mobile-command.yml)
# ruby_lib_core example
@driver.execute_script("mobile: scroll", { "direction" => "down"})
# PHP
// TODO PHP sample
// C#
// TODO C# sample
Description
Execute a variety of native, mobile commands that aren't associated with a specific endpoint
Syntax is execute("mobile: <commandName>", <JSON serializable argument>)
(see Execute Script for more details
on syntax).
List of available commands:
IOS
| Command | Description | Argument | Argument Example |
|---|---|---|---|
| mobile:viewportScreenshot | Like screenshot but only includes contents of viewport |
IOS (XCUITest Only)
| Command | Description | Argument | Argument Example |
|---|---|---|---|
| mobile:startPerfRecord | Starts performance profiling for the device under test | ||
| mobile:stopPerfRecord | Stops performance profiling for the device under test | ||
| mobile:startLogsBroadcast | Starts iOS system logs broadcast websocket on the same host and port where Appium server is running at /ws/session/:sessionId:/appium/syslog endpoint. |
||
| mobile:stopLogsBroadcast | Stops the iOS system logs broadcasting websocket server started by mobile:startLogsBroadcast |
||
| mobile:swipe | refer to Automating Mobile Gestures For iOS With WebDriverAgent/XCTest Backend | ||
| mobile:scroll | refer to Automating Mobile Gestures For iOS With WebDriverAgent/XCTest Backend | ||
| mobile:pinch | refer to Automating Mobile Gestures For iOS With WebDriverAgent/XCTest Backend | ||
| mobile:doubleTap | refer to Automating Mobile Gestures For iOS With WebDriverAgent/XCTest Backend | ||
| mobile:touchAndHold | refer to Automating Mobile Gestures For iOS With WebDriverAgent/XCTest Backend | ||
| mobile:twoFingerTap | refer to Automating Mobile Gestures For iOS With WebDriverAgent/XCTest Backend | ||
| mobile:tap | refer to Automating Mobile Gestures For iOS With WebDriverAgent/XCTest Backend | ||
| mobile:dragFromToForDuration | refer to Automating Mobile Gestures For iOS With WebDriverAgent/XCTest Backend | ||
| mobile:selectPickerWheelValue | refer to Automating Mobile Gestures For iOS With WebDriverAgent/XCTest Backend | ||
| mobile:alert | refer to Automating Mobile Gestures For iOS With WebDriverAgent/XCTest Backend | ||
| mobile:installApp | refer to XCUITest Mobile App Managemenet | ||
| mobile:removeApp | refer to XCUITest Mobile App Managemenet | ||
| mobile:isAppInstalled | refer to XCUITest Mobile App Managemenet | ||
| mobile:launchApp | refer to XCUITest Mobile App Managemenet | ||
| mobile:terminateApp | refer to XCUITest Mobile App Managemenet | ||
| mobile:activateApp | refer to XCUITest Mobile App Managemenet | ||
| mobile:queryAppState | refer to XCUITest Mobile App Managemenet | ||
| mobile:setPasteboard | refer to IOS Pasteboard Guide | ||
| mobile:getPasteboard | refer to IOS Pasteboard Guide | ||
| mobile:installCertificate | refer to IOS Pasteboard Guide | ||
| mobile:getContexts | Retrieve available contexts, along with the url and title associated with each webview (see get contexts) | ||
| mobile:batteryInfo | Reads the battery information from the device under test | ||
| mobile:pressButton | Press a physical button. The supported button name is is home. volumeup and volumedown are available for real devices | {name} |
{name: "home"} |
| mobile:enrollBiometric | Enroll (or unenroll) an iOS Simulator to use biometrics | {isEnabled} |
{isEnabled: true} |
| mobile:sendBiometricMatch | Send a matching or non-matching biometric input to an iOS Simulator. 'type' must be touchId or faceId. Match is a boolean indicating if it's a matching or non-matching input |
{type, match} |
{type: "touchId", match: true} |
| mobile:isBiometricEnrolled | Check if an iOS Simulator is enrolled or not. Returns true if enrolled, false if not enrolled. |
||
| mobile:clearKeychains | Clear the keychains for an iOS Simulator | ||
| mobile:siriCommand | Sends a command to Siri | {text} |
{text: "What time is it?"} |
Android
| Command | Description | Argument | Argument Example |
|---|---|---|---|
| mobile:shell | Execute ADB shell commands (requires server flag --relaxed-security to be set) |
ADB shell string | am start -n com.example.demo/com.example.test.MainActivity |
| mobile:startLogsBroadcast | Starts Android logcat broadcast websocket on the same host and port where Appium is running at /ws/session/:sessionId:/appium/logcat endpoint |
||
| mobile:stopLogsBroadcast | Stops the logcat broadcasting websocket server started by mobile:startLogsBroadcast |
||
| mobile:performEditorAction | Performs the given editor action on the focused input field. The following action names are supported: normal, unspecified, none, go, search, send, next, done, previous. |
{action} | {action: "previous"} |
Android (UiAutomator2 only)
| Command | Description | Argument | Argument Example |
|---|---|---|---|
| mobile:batteryInfo | Reads the battery information from the device under test | ||
| mobile:acceptAlert | Accepts an on-screen alert | Optional button label to click on | |
| mobile:dismissAlert | Dismisses an on-screen alert | Optional button label to click on | |
| mobile:scrollBackTo | Scroll from one element to another | {elementId, elementToId} |
{elementId: 2, elementToId: 1} |
| mobile:viewportScreenshot | Like screenshot but only includes contents of viewport | ||
| mobile:deepLink | Opens a deep-link URL for testing Instant Apps | {url, package} |
{url: "https://www.site.com/", package: "com.site.SomeAndroidPackage"} |
| mobile:getDeviceInfo | Gets device information like manufacturer and model. Read GetDeviceInfo for more details. |
Android (Espresso only)
| Command | Description | Argument | Argument Example |
|---|---|---|---|
| mobile:swipe | Perform the "swipe" view action | {elementId, direction} |
{elementId: 2, direction: "down|up|left|right"} |
| mobile:isToastVisible | Check whether a toast message is visible. text is the mandatory argument. isRegexp is optional. text will be parsed as a regular expression pattern if isRegexp is true. isRegexp is false by default. It returns true if the text exists, or false otherwise. |
{text, isRegexp} |
{ text: 'A toast' }, { text: '^regex$', isRegexp: true } |
| mobile:openDrawer | Open drawer by DrawerAction with gravity. gravity is option. The default is GravityCompat.START. This method blocks until the drawer is fully open. No operation if the drawer is already open. |
{element, gravity} |
{ element: element_id }, { element: element_id, gravity: 3 } |
| mobile:closeDrawer | Close drawer by DrawerAction with gravity. gravity is option. The default is GravityCompat.START. This method blocks until the drawer is fully closed. No operation if the drawer is already closed. |
{element, gravity} |
{ element: element_id }, { element: elementId, gravity: 3 } |
| mobile:setDate | Set date by PickerActions#setDate for DataPicker. | {element, year, monthOfYear, dayOfMonth} |
{element: elementId, year: 2018, monthOfYear: 12, dayOfMonth: 1} |
| mobile:setTime | Set time by PickerActions#setTime for TimePicker. | {element, hours, minutes} |
{element: elementId, hours: 12, minutes: 10} |
| mobile:navigateTo | Action to NavigationView by NavigationViewActions#navigateTo. The view must be a child of a DrawerLayout, of type NavigationView, visible on screen and displayed on screen. | {element, menuItemId} |
{element: elementId, menuItemId: 1} |
| mobile:scrollToPage | Action to ViewPager by ViewPagerActions. scrollTo must be one of first, last, left, right. scrollTo is used by default if scrollTo and scrollToPage are provided. |
{scrollTo, scrollToPage, smoothScroll} |
{element: elementId, scrollTo: 'left', smoothScroll: true}, {element: elementId, scrollToPage: 2} |
| mobile:backdoor | Invoke arbitrary methods defined in Android app. The methods must be public. target is activity, application or element. methods are methods you would like to invoke. elementId is mandatory if target is element. Read docstring of mobileBackdoor method here for more details |
{target, methods, elementId} |
{target: 'activity', methods: [{name: 'method1'}, {name: 'method2', args: [{value: 'hello appium', type: 'java.lang.String'}] }] }, {target: 'element', elementId: elementId, [{name: 'getTypeface'}, {name: 'isItalic'}]} |
| mobile:flashElement | Flashes an element on the screen to visually confirm you are operating on the correct element. Can optionally set durationMillis (in ms) and repeatCount of animation |
{elementId, durationMillis, repeatCount} |
{elementId: "1234-abcd-5678", durationMillis: 1000, repeatCount: 10} |
Support
Appium Server
| Platform | Driver | Platform Versions | Appium Version | Driver Version |
|---|---|---|---|---|
| iOS | XCUITest | 9.3+ | 1.6.0+ | All |
| UIAutomation | 8.0 to 9.3 | All | All | |
| Android | Espresso | ?+ | 1.9.0+ | All |
| UiAutomator2 | ?+ | 1.6.0+ | All | |
| UiAutomator | 4.2+ | All | All | |
| 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 | github.com |
| Ruby | All | www.rubydoc.info |
| PHP | All | github.com |
| C# | All | github.com |
HTTP API Specifications
Endpoint
GET /wd/hub/session/:session_id/execute
URL Parameters
| name | description |
|---|---|
| session_id | ID of the session to route the command to |
JSON Parameters
| name | type | description |
|---|---|---|
| script | string |
The mobile command to execute |
| args | array |
The JSON serializable arguments |
Response
The command result (any)