Desktop is a cross-platform library for navigating and interacting with desktop environments. It can be used to automate applications through the same interfaces that are available to human users.
The library includes the following features:
- Mouse and keyboard input emulation
- Starting and stopping applications
- Finding elements through image template matching
- Scraping text from given regions
- Taking screenshots
- Clipboard management
Windows element selectors are not currently supported, and require the use of RPA.Desktop.Windows
The basic features such as mouse and keyboard input and application control work with a default rpaframework install.
Advanced computer-vision features such as image template matching and OCR require an additional library called rpaframework-recognition.
The dependency should be added separately by specifing it in your conda.yaml as rpaframework-recognition==5.0.1 for example. If installing recognition through pip instead of conda, the OCR feature also requires tesseract.
To automate actions on the desktop, a robot needs to interact with various graphical elements such as buttons or input fields. The locations of these elements can be found using a feature called locators.
A locator describes the properties or features of an element. This information can be later used to locate similar elements even when window positions or states change.
The currently supported locator types are:
|A custom named locator from the locator database, the default.
|Image of an element that is matched to current screen content.
|x (int), y (int)
|Pixel coordinates as absolute position.
|x (int), y (int)
|Pixel coordinates relative to current mouse position.
|width (int), height (int)
|Region of fixed size, around point or screen top-left
|left (int), top (int), right (int), bottom (int)
|Bounding coordinates for a rectangular region.
|text (str), confidence (float, optional)
|Text to find from the current screen.
A locator is defined by its type and arguments, divided by a colon. Some example usages are shown below. Note that the prefix for alias can be omitted as its the default type.
You can also pass internal region objects as locators:
Often it is not enough to have one locator, but instead an element is defined through a relationship of various locators. For this use case the library supports a special syntax, which we will call locator chaining.
An example of chaining:
The supported operators are:
|Base locator relative to the previous one
|and, &&, &
|Both locators should be found
|or, ||, |
|Either of the locators should be found
|The locator should not be found
The library supports storing locators in a database, which contains all of the required fields and various bits of metadata. This enables having one source of truth, which can be updated if a website's or applications's UI changes. Robot Framework scripts can then only contain a reference to a stored locator by name.
The main way to create named locators is with VSCode.
Read more on identifying elements and crafting locators:
- Desktop automation and RPA
- How to find user interface elements using locators and keyboard shortcuts in Windows applications
Keyboard and mouse
Keyboard keywords can emulate typing text, but also pressing various function keys. The name of a key is case-insensitive and spaces will be converted to underscores, i.e. the key Page Down and page_down are equivalent.
The following function keys are supported:
|A generic Shift key. This is a modifier.
|The left Shift key. This is a modifier.
|The right Shift key. This is a modifier.
|A generic Ctrl key. This is a modifier.
|he left Ctrl key. This is a modifier.
|The right Ctrl key. This is a modifier.
|A generic Alt key. This is a modifier.
|The left Alt key. This is a modifier.
|The right Alt key. This is a modifier.
|The AltGr key. This is a modifier.
|A generic command button (Windows / Command / Super key). This may be a modifier.
|The left command button (Windows / Command / Super key). This may be a modifier.
|The right command button (Windows / Command / Super key). This may be a modifier.
|An up arrow key.
|A down arrow key.
|A left arrow key.
|A right arrow key.
|The Enter or Return key.
|The Space key.
|The Tab key.
|The Backspace key.
|The Delete key.
|The Esc key.
|The Home key.
|The End key.
|The Page Down key.
|The Page Up key.
|The Caps Lock key.
|f1 to f20
|The function keys.
|The Insert key. This may be undefined for some platforms.
|The Menu key. This may be undefined for some platforms.
|The Num Lock key. This may be undefined for some platforms.
|The Pause / Break key. This may be undefined for some platforms.
|The Print Screen key. This may be undefined for some platforms.
|The Scroll Lock key. This may be undefined for some platforms.
When controlling the mouse, there are different types of actions that can be done. Same formatting rules as function keys apply. They are as follows:
|Click with left mouse button
|Click with left mouse button
|Double click with left mouse button
|Triple click with left mouse button
|Click with right mouse button
The supported mouse button types are left, right, and middle.
Both Robot Framework and Python examples follow.
The library must be imported first.
The library can open applications and interact with them through keyboard and mouse events.
Targeting can be currently done using coordinates (absolute or relative), but using template matching is preferred.
Elements can be found by text too.
It is recommended to wait for the elements to be visible before trying any interaction. You can also pass region objects as locators.
Another way to find elements by offsetting from an anchor:
Initialize self. See help(type(self)) for accurate signature.