find_element
Thefind_element command finds the first UI element that matches a specified selector strategy.
XPath with Appium Vega Driver, you can use the By.xpath() locator strategy.
Arguments
Common XPath expression components
AXPath expression includes the following components:
- Axis - Specifies the direction of the search, such as descendant, ancestor, and following.
- Node test - Specifies the node type to select, such as element, attribute, or text().
- Predicate - Filters the selected nodes that are based on various conditions, such as attribute values, position, or custom functions.
XPath expression:
find_elements
Thefind_elements command finds multiple UI elements, supports various locator strategies, and returns an array of elements, even if empty. Use this command for:
- Iterating through lists
- Verifying multiple controls
XPath.
Arguments
Comparison of find_element and find_elements
click
Theclick command simulates clicking on a specific element at its center point. Although various locator strategies are available, clicking on elements by their ID provides a reliable and maintainable approach.
Arguments
Theclick command doesn’t require arguments as it operates on a previously located element.
Known limitations
Theclick() command may fail on devices connected to a video capture card instead of a real TV or monitor. The coordinate transformation between the automation toolkit and the display compositor can cause the touch event to land at incorrect coordinates.
Workaround:
- Use D-pad navigation (
setFocus+pressKeyCodewithDPAD_CENTER) instead ofelement.click().
send_keys
Thesend_keys command simulates typing text into an element and expects a string argument.
Arguments
Best practices:
- Verify that the target element has focus and is ready to receive input.
- Check element focus before sending keys. Use commands like
click()to select the element before sending keys. - Add short delays between key sends as rapid or simultaneous input might cause issues on some devices or apps.
get_attribute
Theget_attribute command retrieves the value of a specified attribute for a UI element.
Arguments
List of attributes
get_element_text
Theget_element_text command retrieves the visible text content of a UI element. It returns the text that would be visible to the user, excluding any hidden text.
Arguments
The get_element_text command doesn’t require arguments as it operates on a previously located element.Best practices:
- Verify the element existence before attempting to get its text.
- Handle potential empty text returns appropriately.
- Consider text formatting and special characters in assertions.
- Use with proper wait strategies when needed.
press_keycode
Thepress_keycode command simulates pressing a specific hardware key on the device. Use it with caution as it can impact app state and test flow. It accepts only numerical keycodes (no hexadecimal codes).
Arguments
tap
Thetap command simulates tapping a specific set of coordinates on the screen. This command offers precise control over touch interactions but requires caution.
Arguments
Best practices:
Althoughtap offers fine-grained control, you should prioritize element-based interactions for test stability and maintainability. Use it only when element-based methods are impractical.
is_enabled
Theis_enabled command checks the current state of a UI element. It returns true for enabled (interactive) and false for disabled (non-interactive).
is_enabled with other commands like is_displayed.
Arguments
Theis_enabled command doesn’t take arguments as it operates on a previously located element.
Best practices:
- Use
is_enabledas part of a comprehensive element state check. - Don’t rely on
is_enabledto determine element interactivity. - Implement wait strategies before checking the element state.
is_displayed
Theis_displayed command checks if a UI element is visible on the screen. It returns true for visible and false for hidden.
Arguments
The is_displayed command doesn’t take arguments as it operates on a previously located element.Best practices:
- Use
is_displayedas part of a comprehensive element state check.
implicitly_wait
Theimplicitly_wait command sets how long the driver waits when searching for unavailable elements. Although this command enhances test stability, use it with caution. For complex scenarios, combine implicitly_wait with explicit waits to balance reliability and execution speed.
Arguments
Best practices:
- Set
implicitly_waitat the start of the test. - Reset to a reasonable default (for example, 0 ms) when necessary.
get_window_rect
Theget_window_rect command retrieves the size and position of the current app window relative to the overall screen size.
Example:
Python
x- left coordinate of the windowy- top coordinate of the windowwidth- width of the windowheight- height of the window
Arguments
No arguments are required.Best practices:
Useget_window_rect with other commands to create robust test scripts that handle varying screen sizes and layouts.
get_page_source
Theget_page_source command retrieves the current page source of the app, which represents the underlying UI structure.
Python
Arguments
Theget_page_source command doesn’t require any arguments.
get_screenshot
Theget_screenshot command captures the current app state as a base64-encoded string. Consider user privacy when using this command. Don’t capture digital rights management (DRM) content.
Python
Arguments
No arguments are required for this command.install_app
Theinstall_app command installs an app on the device. The VPKG file path must be available on the host’s (appium server) filesystem. Use this command at the beginning of the test to automate environment setup.
Example:
Python:
Arguments
activate_app
Theactivate_app command launches or brings to the foreground a specified app on the device. This command is useful for testing app switching scenarios or confirms a specific app is active before performing further test actions.
Example:
Python:
Arguments
Best practices
To get the correctappId for launching the app, run vpm list applications.
terminate_app
Theterminate_app command stops the currently running app. Use this command when testing app behavior during forced closures or creating a clean state between test cases.
Example:
Arguments
remove_app
Theremove_app command uninstalls an app from the device.
Example:
Arguments
execute_script
Theexecute_script command runs shell commands or invokes jsonrpc APIs.
To execute shell commands on the device:
appium_driver.execute_script("shell", "echo hello world") #
To invoke jsonrpc APIs not exposed in Appium public interface:
appium_driver.execute_script("jsonrpc: getScreenContext", "")
push_file
Thepush_file command lets you to transfer files directly to a device. You must provide the file content as a base64-encoded string. Use cases include uploading test data, configuration files, or any other files needed during test execution.
Python:
Arguments
pull_file
Thepull_file command lets you transfer files directly from a device.e command returns the file content as a base64-encoded string. Use cases include downloading test results, configuration files, or any other files needed during and after test execution.
Python:
Arguments
D-pad navigation
Theexecute_script function sends Linux input event codes through the jsonrpc: injectInputKeyEvent method. This functionality lets your app simulate user input events programmatically for automation and testing.
The function runs specified commands and key events within a script, enabling D-pad navigation in apps designed for directional pad input.
The table lists the input event codes.
injectInputKeyEvent:

