Introduction

The Windows is a library that can be used for Windows desktop automation.

Library is included in the rpaframework package by default, but as shown in the below example library can be also installed separately without rpaframework.

channels:
  - conda-forge
dependencies:
  - python=3.9.13
  - pip=22.1.2
  - pip:
    - rpaframework-windows==7.0.2 # standalone Windows library (rpaframework includes this library)

About terminology

ControlType is a value referred to by locator keys type: or control. Represents type of application object, which can be e.g. Window, Button or ListItem.

Element is an entity of an application structure (e.g. certain button in a window), which can be identified by a locator. (also referred as Control)

WindowsElement is an library container object for the Element. All the keywords returning elements, will in fact return WindowsElement`s. The ones accepting `locator or root_element as arguments, will accept WindowsElement as an argument value. (locator accepts strings as well)

Structure of the WindowsElement

class WindowsElement:
    item: Control        # `item` contains object instance of the element
    locator: str         # `locator` that found this element
    name: str            # `Name` attribute of the element
    automation_id: str   # `AutomationId` attribute of the element
    control_type: str    # `ControlTypeName` attribute of the element
    class_name: str      # `ClassName` attribute of the element
    left: int            # element's rectangle left coordinate
    right: int           # element's rectangle right coordinate
    top: int             # element's rectangle top coordinate
    bottom: int          # element's rectangle bottom coordinate
    width: int           # element's rectangle horizontal width
    height: int          # element's rectangle vertical height
    xcenter: int         # element's rectangle center point x coordinate
    ycenter: int         # element's rectangle center point y coordinate

Example of the WindowsElement usage

${rows}=    Get Elements    class:DataGridRow
# ${rows} is a list of `WindowsElement`s
FOR    ${row}    IN    @{rows}
    Log To Console   ${row.name}                # access `WindowsElement`
    Log To Console   ${row.item.AutomationId}   # access `WindowsElement.item` directly
    Log To Console   ${row.item.Name}           # same as `${row.name}`
END

Locators

Locators are based on different strategies that can used identify Control object.

Available strategies that can be used for the locators:

Key Maps to search property
name Name
class ClassName
type ControlType
control ControlType
id AutomationId
automationid AutomationId
regex RegexName
subname SubName
index foundIndex (int)
offset offset coordinates (x (int), y (int)) from control center
executable target window by its executable name
handle target window handle (int)
desktop SPECIAL target desktop, no value for the key e.g. desktop:desktop and name:Calculator
process NOT YET SUPPORTED target window by its executable's process id
depth searchDepth (int) for finding Control (default 8)
path target element by its index-based path traversal (e.g. path:2|3|8|2)

About root element on locators

Locators work on currently active root element. At the start root element is the whole desktop. There are different ways on changing this root element.

Keyword Control Window is the most common method of setting certain system window as a root element for further actions using locators. In the absence of a provided root_element parameter, here's how you can control the default root element resolving:

  • Set Anchor: Sets the active anchor window from which the search begins.
  • Control Window: Controls and focuses on a window and marks it as the current active window, from which all the subsequent searches will start from in the absence of a set anchor.
  • If there's no set anchor nor active window, then the last resort will be the "Desktop" element itself.

Locators themselves support cascading syntax (denoted by character > in the locator string), which can denote root element in "parent (root) & child" terms.

For example.

Click  id:controls > id:activate

On the above example the left side of the > character, id:controls, represents the root element (can be called as "parent element" in this case). Right side of the locator string, id:activate, represents "child" element and it will be searched under the "parent element".

This way element search is more efficient, because search are restricted to certain section of element tree which can be quite huge especially on the desktop level and in certain applications.

Keyword examples:

Control Window    name:Calculator
Control Window    Calculator  # will execute search by 'name:Calculator'
Control Window    executable:Spotify.exe

some example locators, and can be omitted ie. space between locator keys means the same thing as and:

id:clearButton
type:Group and name:"Number pad" > type:Button and index:4
type:Group and name:"Number pad" > control:Button index:5
id:Units1 > name:${unit}
class:Button offset:370,0

About locator restrictions

Visual locators are not supported in this library and they can't be used in the same chain with these Windows locators. Visual locators are supported by the RPA.Desktop library. Locator chaining (image and Windows locators) support will be added in the future.

Locator syntax does not yet support OR operation (only AND operations).

About search depth

The library does element search depth by default to the level of 8. This means that locator will look into 8 levels of elements under element tree of the root element. This can lead into situation where element can't be found. To fix this it is recommended to set root element which can be found within 8 levels OR defining depth in the locator string to a bigger value, e.g. id:deeplyNestedButton depth:16. Useful keywords for setting root element are Control Window, Set Anchor and Get Element.

About the path strategy

When automation IDs and names aren't enough (or not reliable), then you can fallback to the positions of elements in a tree. This can be achieved using the path: strategy to specify a list of element positions which indicates how to traverse the tree from parent to child beginning with the resolved root.

Example: Calculator > path:2|3|2|8|2 - this locator looks for the "Calculator" window, then it looks for the 2nd direct child and then it looks for the 3rd one of the previous child and so on until it consumes the path completely. (indexes start with 1)

An alternative way to get the whole tree to explore it yourself would be to use the Print Tree keyword.

Keyboard and mouse

Keys for the keyboard actions are given using uiautomation specification.

Special keys which are given within {} syntax.

Key Maps to action
LBUTTON Left mouse button
RBUTTON Right mouse button
CANCEL Control-break processing
MBUTTON Middle mouse button (three-button mouse)
XBUTTON1 X1 mouse button
XBUTTON2 X2 mouse button
BACK BACKSPACE key
TAB TAB key
CLEAR CLEAR key
RETURN ENTER key
ENTER ENTER key
SHIFT SHIFT key
CTRL CTRL key
CONTROL CTRL key
ALT ALT key
PAUSE PAUSE key
CAPITAL CAPS LOCK key
KANA IME Kana mode
HANGUEL IME Hanguel mode (maintained for compatibility; use VK_HANGUL)
HANGUL IME Hangul mode
JUNJA IME Junja mode
FINAL IME final mode
HANJA IME Hanja mode
KANJI IME Kanji mode
ESC ESC key
ESCAPE ESC key
CONVERT IME convert
NONCONVERT IME nonconvert
ACCEPT IME accept
MODECHANGE IME mode change request
SPACE SPACEBAR
PRIOR PAGE UP key
PAGEUP PAGE UP key
NEXT PAGE DOWN key
PAGEDOWN PAGE DOWN key
END END key
HOME HOME key
LEFT LEFT ARROW key
UP UP ARROW key
RIGHT RIGHT ARROW key
DOWN DOWN ARROW key
SELECT SELECT key
PRINT PRINT key
EXECUTE EXECUTE key
SNAPSHOT PRINT SCREEN key
PRINTSCREEN PRINT SCREEN key
INSERT INS key
INS INS key
DELETE DEL key
DEL DEL key
HELP HELP key
WIN Left Windows key (Natural keyboard)
LWIN Left Windows key (Natural keyboard)
RWIN Right Windows key (Natural keyboard)
APPS Applications key (Natural keyboard)
SLEEP Computer Sleep key
NUMPAD0 Numeric keypad 0 key
NUMPAD1 Numeric keypad 1 key
NUMPAD2 Numeric keypad 2 key
NUMPAD3 Numeric keypad 3 key
NUMPAD4 Numeric keypad 4 key
NUMPAD5 Numeric keypad 5 key
NUMPAD6 Numeric keypad 6 key
NUMPAD7 Numeric keypad 7 key
NUMPAD8 Numeric keypad 8 key
NUMPAD9 Numeric keypad 9 key
MULTIPLY Multiply key
ADD Add key
SEPARATOR Separator key
SUBTRACT Subtract key
DECIMAL Decimal key
DIVIDE Divide key
F1 F1 key
F2 F2 key
F3 F3 key
F4 F4 key
F5 F5 key
F6 F6 key
F7 F7 key
F8 F8 key
F9 F9 key
F10 F10 key
F11 F11 key
F12 F12 key
F13 F13 key
F14 F14 key
F15 F15 key
F16 F16 key
F17 F17 key
F18 F18 key
F19 F19 key
F20 F20 key
F21 F21 key
F22 F22 key
F23 F23 key
F24 F24 key
NUMLOCK NUM LOCK key
SCROLL SCROLL LOCK key
LSHIFT Left SHIFT key
RSHIFT Right SHIFT key
LCONTROL Left CONTROL key
LCTRL Left CONTROL key
RCONTROL Right CONTROL key
RCTRL Right CONTROL key
LALT Left MENU key
RALT Right MENU key
BROWSER_BACK Browser Back key
BROWSER_FORWARD Browser Forward key
BROWSER_REFRESH Browser Refresh key
BROWSER_STOP Browser Stop key
BROWSER_SEARCH Browser Search key
BROWSER_FAVORITES Browser Favorites key
BROWSER_HOME Browser Start and Home key
VOLUME_MUTE Volume Mute key
VOLUME_DOWN Volume Down key
VOLUME_UP Volume Up key
MEDIA_NEXT_TRACK Next Track key
MEDIA_PREV_TRACK Previous Track key
MEDIA_STOP Stop Media key
MEDIA_PLAY_PAUSE Play/Pause Media key
LAUNCH_MAIL Start Mail key
LAUNCH_MEDIA_SELECT Select Media key
LAUNCH_APP1 Start Application 1 key
LAUNCH_APP2 Start Application 2 key
OEM_1 Used for miscellaneous characters; it can vary by keyboard.For the US standard keyboard, the ';:' key
OEM_PLUS For any country/region, the '+' key
OEM_COMMA For any country/region, the ',' key
OEM_MINUS For any country/region, the '-' key
OEM_PERIOD For any country/region, the '.' key
OEM_2 Used for miscellaneous characters; it can vary by keyboard.
OEM_3 Used for miscellaneous characters; it can vary by keyboard.
OEM_4 Used for miscellaneous characters; it can vary by keyboard.
OEM_5 Used for miscellaneous characters; it can vary by keyboard.
OEM_6 Used for miscellaneous characters; it can vary by keyboard.
OEM_7 Used for miscellaneous characters; it can vary by keyboard.
OEM_8 Used for miscellaneous characters; it can vary by keyboard.
OEM_102 Either the angle bracket key or the backslash key on the RT 102-key keyboard
PROCESSKEY IME PROCESS key
PACKET Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KeyUp
ATTN Attn key
CRSEL CrSel key
EXSEL ExSel key
EREOF Erase EOF key
PLAY Play key
ZOOM Zoom key
NONAME Reserved
PA1 PA1 key
OEM_CLEAR Clear key

Examples.

lib = Windows()
# {Ctrl}, {Delete} ... are special keys' name in SpecialKeyNames.
lib.send_keys('{Ctrl}a{Delete}{Ctrl}v{Ctrl}s{Ctrl}{Shift}s{Win}e{PageDown}') #press Ctrl+a, Delete, Ctrl+v, Ctrl+s, Ctrl+Shift+s, Win+e, PageDown
lib.send_keys('{Ctrl}(AB)({Shift}(123))') #press Ctrl+A+B, type '(', press Shift+1+2+3, type ')', if '()' follows a hold key, hold key won't release util ')'
lib.send_keys('{Ctrl}{a 3}') #press Ctrl+a at the same time, release Ctrl+a, then type 'a' 2 times
lib.send_keys('{a 3}{B 5}') #type 'a' 3 times, type 'B' 5 times
lib.send_keys('{{}Hello{}}abc {a}{b}{c} test{} 3}{!}{a} (){(}{)}') #type: '{Hello}abc abc test}}}!a ()()'
lib.send_keys('0123456789{Enter}')
lib.send_keys('ABCDEFGHIJKLMNOPQRSTUVWXYZ{Enter}')
lib.send_keys('abcdefghijklmnopqrstuvwxyz{Enter}')
lib.send_keys('`~!@#$%^&*()-_=+{Enter}')
lib.send_keys('[]{{}{}}\|;:'",<.>/?{Enter}')

Using access key of the element (element property -> AccessKey 'alt+s'). The (+s) means that previous special key is kept down until closing parenthesis is reached.

On the below example this means that 'ALT' key is pressed down, then '+' and 's' keys are pressed down before they are all released up.

Send Keys   keys={Alt}(+s)

Mouse clicks can be executed with keywords specific for a type of a click, e.g. Click (normal click), Double Click and Right Click.

How to inspect

Most common, and recommended by Microsoft, inspector tool for Windows is Accessibility Insights that can be installed separately. Other options are tools Inspect Object and UI Automation Verify, which can be accessed by installing Windows SDK.

A more programmatic approach is to run Print Tree    log_as_warnings=${True} keyword and then observe in the logs the found elements structure starting from Desktop (or the currently set anchor / active window) as root. (refer to keyword's documentation for more details)

Recording

The package provides some rudimentary inspecting and recording via the windows-record script, which can be started through the command line (in an environment containing the rpaframework-windows installation).

Recording inspects elements on mouse click and can be stopped by pressing the ESC key. Expected console output:

C:\Users\User\robots\> windows-record -v  # or > python -m RPA.Windows -v
Mouse recording started. Use ESC to stop recording.

--------------------------------------------------------------------------------
Copy-paste the code below into your *** Tasks *** or *** Keywords ***
--------------------------------------------------------------------------------

Control Window    name:Calculator and type:WindowControl and class:ApplicationFrameWindow  # handle:9569486
Click    name:Calculator and id:TitleBar and type:WindowControl and class:ApplicationFrameTitleBarWindow and path:1
Click    name:"Display is 0" and id:CalculatorResults and type:TextControl and path:2|3|2|2
Click    name:Eight and id:num8Button and type:ButtonControl and class:Button and path:2|3|2|8|9
Click    name:Nine and id:num9Button and type:ButtonControl and class:Button and path:2|3|2|8|10
Click    name:Clear and id:clearButton and type:ButtonControl and class:Button and path:2|3|2|5|3

--------------------------------------------------------------------------------

Check our Portal example in order to learn more abot the path: strategy in locators and how to record elements displaying their paths: https://robocorp.com/portal/robot/robocorp/example-windows-element-path

Video recorded demo on how to run the recorder script from VSCode: https://www.loom.com/share/2807372359f34b9cbe1bc2df9194ec68

Caveats

  • Make sure your display scaling is set to 100%, otherwise you might encounter issues when clicking or interacting with elements. (since offsets and coordinates get distorted)
  • Disturbing the automation (like interacting with your mouse/keyboard) or having other apps obstructing the process interacting with your app of interest will most probably affect the expected behaviour. In order to avoid this, try controlling the app's main window right before sending clicks or keys. And keep targeting elements through string locators, as interacting with Windows element objects previously retrieved will not work as expected in a future altered state of the app (changes under the element structure).

Example: Robot Framework

The library must be imported first.

*** Settings ***
Library    RPA.Windows

Windows Calculator automation task

*** Tasks ***
Do some calculations
    [Setup]  Windows Run   calc.exe

    Control Window    name:Calculator
    Click    id:clearButton
    Send Keys   keys=96+4=
    ${result} =    Get Attribute    id:CalculatorResults    Name
    Log To Console    ${result}

    @{buttons} =  Get Elements  type:Group and name:"Number pad" > type:Button
    FOR  ${button}  IN  @{buttons}
        Log To Console   ${button}
    END

    [Teardown]   Close Current Window

Example: Python

from RPA.Windows import Windows

library = Windows()

def test_do_some_calculations():
    library.windows_run("calc.exe")
    try:
        library.control_window("name:Calculator")
        library.click("id:clearButton")
        library.send_keys(keys="96+4=")
        result = library.get_attribute("id:CalculatorResults", "Name")
        print(result)
        buttons = library.get_elements(
            'type:Group and name:"Number pad" > type:Button'
        )
        for button in buttons:
            print(button)
    finally:
        library.close_current_window()

Importing

Arguments

locators_path
= None
<str><None>

Documentation

Initialize self. See help(type(self)) for accurate signature.

Keywords

Documentation

Clears control anchor set by Set Anchor

This means that all following keywords accessing elements will use active window or desktop as root element.

Arguments

locator <WindowsElement><str> wait_time
= None
<float><None> timeout
= None
<float><None>

Tags

action,
mouse

Documentation

Mouse click on element matching given locator.

Exception ActionNotPossible is raised if element does not allow Click action.

locator:String locator or element object.
wait_time:time to wait after click, default is a library wait_time, see keyword Set Wait Time
timeout:float value in seconds, see keyword Set Global Timeout
return:WindowsElement object

Example:

Click  id:button1
Click  id:button2 offset:10,10
${element}=  Click  name:SendButton  wait_time=5.0

Tags

window

Documentation

Closes current active window or logs a warning message.

return:True if close was successful, False if not

Example:

${status}=  Close Current Window

Arguments

locator
= None
<WindowsElement><str><None> timeout
= None
<float><None>

Tags

window

Documentation

Closes identified windows or logs the problems.

locator:String locator or Control element.
timeout:float value in seconds, see keyword Set Global Timeout
return:How many windows were found and closed.

Example:

${closed_count} =     Close Window    Calculator

Arguments

locator
= None
<WindowsElement><str><None> foreground
= True
<bool> wait_time
= None
<float><None> timeout
= None
<float><None>

Tags

window

Documentation

Get control of child window of the active window by locator.

locator:string locator or Control element
foreground:True to bring window to foreground
wait_time:time to wait after activeting a window
timeout:float value in seconds, see keyword Set Global Timeout
return:WindowsElement object

Example:

Control Window   subname:"Sage 50" type:Window
# actions on the main application window
# ...
# get control of child window of Sage application
Control Child Window   subname:"Test Company" depth:1

Arguments

locator
= None
<WindowsElement><str><None> foreground
= True
<bool> wait_time
= None
<float><None> timeout
= None
<float><None> main
= True
<bool>

Tags

window

Documentation

Controls the window defined by the locator.

This means that this window is used as a root element for all the following keywords using locators.

Returns WindowsElement.

locator:string locator or Control element
foreground:True to bring window to foreground
wait_time:time to wait after activating a window
timeout:float value in seconds, see keyword Set Global Timeout
main:on True (default) starts the search from desktop level, on False it will continue to search for child elements given the set anchor or current active window
return:WindowsElement object

Example:

Control Window   Calculator
Control Window   name:Calculator
Control Window   subname:Notepad
Control Window   regex:.*Notepad
${window}=  Control Window   executable:Spotify.exe

Tags

window

Documentation

Disables process iteration in List Windows keyword.

Arguments

locator <WindowsElement><str> wait_time
= None
<float><None> timeout
= None
<float><None>

Tags

action,
mouse

Documentation

Double mouse click on element matching given locator.

Exception ActionNotPossible is raised if element does not allow Click action.

locator:String locator or element object.
wait_time:time to wait after click, default is a library wait_time, see keyword Set Wait Time
timeout:float value in seconds, see keyword Set Global Timeout
return:WindowsElement object

Example:

${element}=  Double Click  name:ResetButton

Arguments

source_element <WindowsElement><str> target_element <WindowsElement><str> speed
= 1.0
<float><None> copy
= False
<bool><None> wait_time
= 1.0
<float><None>

Tags

action,
mouse

Documentation

Drag and drop the source element into target element.

source:source element for the operation
target:target element for the operation
speed:adjust speed of operation, bigger value means more speed
copy:on True does copy drag and drop, defaults to move
wait_time:time to wait after drop, default 1.0 seconds

Example:

# copying a file, report.html, from source (File Explorer) window
# into a target (File Explorer) Window
# locator
Drag And Drop
...    name:C:\temp type:Windows > name:report.html type:ListItem
...    name:%{USERPROFILE}\Documents\artifacts type:Windows > name:"Items View"
...    copy=True

Example:

# moving *.txt files into subfolder within one (File Explorer) window
${source_dir}=    Set Variable    %{USERPROFILE}\Documents\test
Control Window    name:${source_dir}
${files}=    Find Files    ${source_dir}${/}*.txt
# first copy files to folder2
FOR    ${file}    IN    @{files}
    Drag And Drop    name:${file.name}    name:folder2 type:ListItem    copy=True
END
# second move files to folder1
FOR    ${file}    IN    @{files}
    Drag And Drop    name:${file.name}    name:folder1 type:ListItem
END

Tags

window

Documentation

Enables process iteration in List Windows keyword.

Arguments

locator
= None
<WindowsElement><str><None>

Tags

window

Documentation

Bring the current active window or the window defined by the locator to the foreground.

locator:string locator or Control element
return:WindowsElement object

Example:

${window}=  Foreground Window   Calculator

Arguments

locator <WindowsElement><str> attribute <str>

Documentation

Get attribute value of the element defined by the locator.

locator:string locator or Control element
attribute:name of the attribute to get
return:value of attribute

Example:

${id}=   Get Attribute  type:Edit name:firstname   AutomationId

Arguments

locator
= None
<WindowsElement><str><None> search_depth
= 8
<int> root_element
= None
<WindowsElement><None> timeout
= None
<float><None>

Documentation

Get a Control Windows element defined by the locator.

The returned element can be used instead of a locator string for other keywords accepting the locator parameter. Keyword Get Attribute can be used to read element attribute values.

If locator is None, then the returned element will be in this priority:

  1. root_element if provided.
  2. Anchor element if that has been previously set with Set Anchor.
  3. Current active window if that has been set with Control Window.
  4. Last resort is the "Desktop" element.
locator:Locator as a string or as an element object.
search_depth:How deep the element search will traverse. (default 8)
root_element:Will be used as search root element object if provided.
timeout:After how many seconds (float) to give up on search. (see keyword Set Global Timeout)
returns:The identified WindowsElement object.

Example: Robot Framework

*** Tasks ***
Set Text Into Notepad Window
    Windows Run    Notepad
    Control Window      subname:Notepad
    ${element} =    Get Element    regex:"Text (E|e)ditor"
    Set Value    ${element}    note to myself

Example: Python

from RPA.Windows import Windows

lib = Windows()
lib.windows_run("calc.exe")
one_btn = lib.get_element("Calculator > path:2|3|2|8|2")
lib.close_window("Calculator")

Arguments

locator
= None
<WindowsElement><str><None> search_depth
= 8
<int> root_element
= None
<WindowsElement><None> timeout
= None
<float><None> siblings_only
= True
<bool>

Documentation

Get a list of elements matching the locator.

By default, only the siblings (similar elements on the same level) are taken into account. In order to search globally, turn siblings_only off, but be aware that this will take more time to process.

Note that if the syntax parent_locator > child_locator is used in the locator, it is assumed that parent_locator returns a singular element - i.e. if the locator parent_locator returns multiple elements, only the first result is used for further processing, even if siblings_only is off.

For more details on the rest of parameters, take a look at the Get Element keyword.

locator:Locator as a string or as an element object.
search_depth:How deep the element search will traverse. (default 8)
root_element:Will be used as search root element object if provided.
timeout:After how many seconds (float) to give up on search. (see keyword Set Global Timeout)
siblings_only:Filter for elements on the same level as the initially found one. Turn it off for a global search. (True by default)
returns:A list of matching WindowsElement objects.

Example: Robot Framework

*** Tasks ***
Get Headers On Same Level
    Set Anchor      id:DataGrid
    @{elements} =   Get Elements    type:HeaderItem
    FOR    ${element}    IN    @{elements}
        Log To Console    ${element.name}
    END

Get All Calculator Buttons Matching Expression
    Windows Run    Calc
    Control Window    subname:Calc
    @{buttons} =    Get Elements    class:Button regex:.*o.*
    ...     siblings_only=${False}
    Log List    ${buttons}
    ${length} =     Get Length      ${buttons}
    Log To Console      Number of buttons: ${length}

Arguments

locator <WindowsElement><str>

Tags

action

Documentation

Get text from Control element defined by the locator.

Exception ActionNotPossible is raised if element does not allow GetWindowText action.

locator:String locator or element object.
return:value of WindowText attribute of an element

Example:

${date} =  Get Text   type:Edit name:"Date of birth"

Arguments

locator <WindowsElement><str>

Tags

action

Documentation

Get the value of the element defined by the provided locator.

The ActionNotPossible exception is raised if the identified element doesn't support value retrieval.

locator:String locator or element object.
returns:Optionally the value of the identified element.

Example: Robot Framework

${value} =   Get Value   type:DataItem name:column1

Example: Python

from RPA.Windows import Windows

lib_win = Windows()
text = lib_win.get_value("Rich Text Window")
print(text)

Arguments

locator <WindowsElement><str>

Tags

action

Documentation

Get the selection state of the element defined by the provided locator.

The ActionNotPossible exception is raised if the identified element doesn't support selection item retrieval.

locator:String locator or element object.
returns:Optionally the selection state of the identified element, as a boolean.

Example: Robot Framework

${value} =   Is Selected   type:RadioButtonControl name:Apple

Example: Python

from RPA.Windows import Windows

lib_win = Windows()
value = lib_win.is_selected("type:RadioButtonControl name:Apple")
print(value)

Arguments

locator <WindowsElement><str>

Documentation

List all element attributes.

locator:string locator or Control element
return:list of element attributes (strings)

Arguments

icons
= False
<bool> icon_save_directory
= None
<str><None>

Tags

window

Documentation

List all window element on the system.

icons:on True dictionary will contain Base64 string of the icon, default False
icon_save_directory:
 if set will save retrieved icons into this filepath, by default icon files are not saved
return:list of dictionaries containing information about Window elements

Example:

${windows}=  List Windows
FOR  ${window}  IN  @{windows}
    Log  Window title:${window}[title]
    Log  Window process name:${window}[name]
    Log  Window process id:${window}[pid]
    Log  Window process handle:${window}[handle]
END

Arguments

locator
= None
<WindowsElement><str><None>

Tags

window

Documentation

Maximize the current active window or the window defined by the locator.

locator:string locator or element
return:WindowsElement object

Example:

${window} =    Maximize Window  # Current active window
Maximize Window    executable:Spotify.exe

Arguments

locator <WindowsElement><str> wait_time
= None
<float><None> timeout
= None
<float><None>

Tags

action,
mouse

Documentation

Right mouse click on element matching given locator.

Exception ActionNotPossible is raised if element does not allow Click action.

locator:String locator or element object.
wait_time:time to wait after click, default is a library wait_time, see keyword Set Wait Time
timeout:float value in seconds, see keyword Set Global Timeout
return:WindowsElement object

Example:

${element}=  Middle Click  name:button2

Arguments

locator
= None
<WindowsElement><str><None>

Tags

window

Documentation

Minimize the current active window or the window defined by the locator.

locator:string locator or element
return:WindowsElement object

Example:

${window} =    Minimize Window  # Current active window
Minimize Window    executable:Spotify.exe

Arguments

locator
= None
<WindowsElement><str><None> max_depth
= 8
<int> capture_image_folder
= None
<str><None> log_as_warnings
= False
<bool> return_structure
= False
<bool>

Documentation

Print a tree of control elements.

A Windows application structure can contain multilevel element structure. Understanding this structure is crucial for creating locators. (based on controls' details and their parent-child relationship)

This keyword can be used to output logs of application's element structure, starting with the element defined by the provided locator as root. Switch the return_structure parameter to True to get a tree of elements returned as well. (off by default to save memory)

  • The printed structure displays a tree prefixed with "depth" - "position" so you know how deep (0 means root) in the tree you are and on what position (1-indexed) the child you're looking for is.
  • The returned structure is a dictionary with all the children flattened per depth level. Additionally, these WindowsElement objects contain a relevant locator composed of "root > path" which will help to identify the element in the tree.

Portal example: https://robocorp.com/portal/robot/robocorp/example-windows-element-path

locator:The root of the tree to output.
max_depth:Maximum depth level. (defaults to 8)
capture_image_folder:
 If set, controls' images will be captured in this path.
log_as_warnings:
 Enables highlighted logs (at the beginning of the log file as warnings) and increases visibility in the output console.
return_structure:
 A flattened tree with all the elements collated by level will be returned if this is enabled.
returns:Optionally a dictionary of children per depth level when return_structure is enabled.

Example: Robot Framework

*** Tasks ***
Display Element Structure
    ${tree} =   Print Tree      Calculator > path:2|3|2|8
    ...     return_structure=${True}
    Log To Console      ${tree}

Example: Python

from RPA.Windows import Windows

lib = Windows()
tree = lib.print_tree("Calculator > path:2|3|2|8", return_structure=True)
print(tree)

Arguments

locator
= None
<WindowsElement><str><None>

Tags

window

Documentation

Window restore the current active window or the window defined by the locator.

locator:string locator or element
return:WindowsElement object

Example:

${window} =    Restore Window  # Current active window
Restore Window    executable:Spotify.exe

Arguments

locator <WindowsElement><str> wait_time
= None
<float><None> timeout
= None
<float><None>

Tags

action,
mouse

Documentation

Right mouse click on element matching given locator.

Exception ActionNotPossible is raised if element does not allow Click action.

locator:String locator or element object.
wait_time:time to wait after click, default is a library wait_time, see keyword Set Wait Time
timeout:float value in seconds, see keyword Set Global Timeout
return:WindowsElement object

Example:

${element}=  Right Click  name:MenuButton

Arguments

locator <WindowsElement><str> filename <str><Path>

Tags

action

Documentation

Take a screenshot of the element defined by the locator.

An ActionNotPossible exception is raised if the element doesn't allow being captured.

locator:String locator or element object.
filename:Image file name/path. (can be absolute/relative)
raises ActionNotPossible:
 When the element can't be captured.
returns:Absolute file path of the taken screenshot image.

Example: Robot Framework

*** Tasks ***
Take Screenshots
    Screenshot    desktop    desktop.png
    Screenshot    subname:Notepad    ${OUTPUT_DIR}${/}notepad.png

Example: Python

from RPA.Windows import Windows
lib = Windows()

def take_screenshots():
    lib.screenshot("desktop", "desktop.png")
    lib.screenshot("subname:Notepad", "output/notepad.png")

Arguments

locator <WindowsElement><str> value <str>

Tags

action

Documentation

Select a value on the passed element if such action is supported.

The ActionNotPossible exception is raised when the element does not allow the Select action. This is usually used with combo box elements.

locator:String locator or element object.
value:String value to select on Control element
returns:The controlled Windows element.

Example: Robot Framework

* Settings * Library RPA.Windows

* Tasks * Set Notepad Size

System Message: ERROR/3 (<string>, line 17)

Unexpected indentation.
Select id:FontSizeComboBox 22

Example: Python

from RPA.Windows import Windows

lib = Windows()

def set_notepad_size():
    lib.select("id:FontSizeComboBox", "22")

Arguments

locator
= None
<WindowsElement><str><None> keys
= None
<str><None> interval
= 0.01
<float> wait_time
= None
<float><None> send_enter
= False
<bool>

Documentation

Send keys to desktop, current window or to Control element defined by given locator.

If locator is None then keys are sent to desktop.

Exception ActionNotPossible is raised if element does not allow SendKeys action.

locator:Optional string locator or element object.
keys:The keys to send.
interval:Time between each sent key. (defaults to 0.01 seconds)
wait_time:Time to wait after sending all the keys. (defaults to library's set value, see keyword Set Wait Time)
send_enter:If True then the {Enter} key is pressed at the end of the sent keys.
returns:The element identified through locator.

Example:

Send Keys  desktop   {Ctrl}{F4}
Send Keys  keys={Ctrl}{F4}   # locator will be NONE, keys sent to desktop
Send Keys  id:input5  username   send_enter=${True}
${element}=   Get Element   id:pass
Send Keys  ${element}  password   send_enter=${True}

Arguments

locator <WindowsElement><str> timeout
= None
<float><None>

Documentation

Set anchor to an element specified by the locator.

All following keywords using locators will use this element as a root element. Specific use case could be setting anchor to TableControl element and then getting column data belonging to that TableControl element.

To release anchor call Clear Anchor keyword.

locator:string locator or Control element
timeout:timeout in seconds for element lookup (default 10.0)

Example:

Set Anchor  type:Table name:Orders depth:16
FOR  ${row}  IN RANGE  200
    ${number}=  Get Value   name:number row ${row}
    Exit For Loop If   $number == ${EMPTY}
    ${sum}=  Get Value   name:sum row ${row}
    Log   Order number:${number} has sum:{sum}
END
Clear Anchor

Arguments

locator <WindowsElement><str>

Tags

action

Documentation

Set view focus to the element defined by the locator.

locator:String locator or element object.

Example:

Set Focus  name:Buy type:Button

Arguments

timeout <float>

Tags

action

Documentation

Set global timeout for element search. Applies also to Control Window keyword.

By default, the library has a timeout of 10 seconds.

timeout:float value in seconds
return:previous timeout value

Example:

${old_timeout}=  Set Global Timeout  20
${old_timeout}=  Set Global Timeout  9.5

Arguments

simulate <bool>

Tags

action

Documentation

Enable or disable mouse movement simulation during clicks and other actions.

Returns the previous set value as True/False.

simulate:Decide whether to simulate the move. (OFF by default)
returns:Previous state.

Example: Robot Framework

*** Tasks ***
Disable Mouse Move
    ${previous} =   Set Mouse Movement      ${True}
    Log To Console   Previous mouse simulation: ${previous} (now enabled)

Example: Python

from RPA.Windows import Windows

lib_win = Windows()
previous = lib_win.set_mouse_movement(True)
print(f"Previous mouse simulation: {previous} (now enabled)")

Arguments

locator
= None
<WindowsElement><str><None> value
= None
<str><None> append
= False
<bool> enter
= False
<bool> newline
= False
<bool> send_keys_fallback
= True
<bool> validator
= <function set_value_validator at 0x00000252AC0078B0>
<Callable><None>

Tags

action

Documentation

Set value of the element defined by the locator.

Note: An anchor will work only on element structures where you can rely on the stability of that root/child element tree, as remaining the same. Usually these kind of structures are tables. (but not restricted to)

Note: It is important to set append=${True} if you want to keep the current text in the element. Other option is to read the current text into a variable, then modify that value as you wish and pass it to the Set Value keyword for a complete text replacement. (without setting the append flag)

The following exceptions may be raised:

  • ActionNotPossible if the element does not allow the SetValue action to be run on it nor having send_keys_fallback=${True}.
  • ValueError if the new value to be set can't be set correctly.
locator:String locator or element object.
value:String value to be set.
append:False for setting the value, True for appending it. (OFF by default)
enter:Set it to True to press the Enter key at the end of the input. (nothing is pressed by default)
newline:Set it to True to add a new line at the end of the value. (no EOL included by default; this won't work with send_keys_fallback enabled)
send_keys_fallback:
 Tries to set the value by sending it through keys if the main way of setting it fails. (enabled by default)
validator:Function receiving two parameters post-setting, the expected and the current value, which returns True if the two values match. (by default, the keyword will raise if the values are different, set this to None to disable validation or pass your custom function instead)
returns:The element object identified through the passed locator.

Example: Robot Framework

*** Tasks ***
Set Values In Notepad
    Set Value   type:DataItem name:column1   ab c  # Set value to "ab c"
    # Press ENTER after setting the value.
    Set Value    type:Edit name:"File name:"    console.txt   enter=${True}

    # Add newline (manually) at the end of the string. (Notepad example)
    Set Value    name:"Text Editor"  abc\n
    # Add newline with parameter.
    Set Value    name:"Text Editor"  abc   newline=${True}

    # Clear Notepad window and start appending text.
    Set Anchor  name:"Text Editor"
    # All the following keyword calls will use the anchor element as a
    #  starting point, UNLESS they specify a locator explicitly or
    #  Clear Anchor is used.
    ${time} =    Get Time
    # Clears with append=${False}. (default)
    Set Value    value=The time now is ${time}
    # Append text and add a newline at the end.
    Set Value    value= and it's the task run time.   append=${True}
    ...    newline=${True}
    # Continue appending and ensure a new line at the end by pressing
    #  the Enter key this time.
    Set Value    value=But this will appear on the 2nd line now.
    ...    append=${True}   enter=${True}   validator=${None}

Example: Python

from RPA.Windows import Windows

lib_win = Windows()
locator = "Document - WordPad > Rich Text Window"
elem = lib_win.set_value(locator, value="My text", send_keys_fallback=True)
text = lib_win.get_value(elem)
print(text)

Arguments

wait_time <float>

Tags

action

Documentation

Set library wait time for action keywords.

The wait_time is spent after each keyword performing mouse or keyboard action.

Library default wait_time is 0.5

Returns value of the previous wait_time value.

wait_time:float value (in seconds), e.g. 0.1
return:previous wait value

Example:

${old_wait_time}=  Set Wait Time  0.2

Arguments

text <str> wait_time
= 3.0
<float>

Tags

window

Documentation

Use Windows Run window to launch an application.

Activated by pressing Win + R. Then the app name is typed in and finally the "Enter" key is pressed.

text:Text to enter into the Run input field. (e.g. Notepad)
wait_time:Time to sleep after the searched app is executed. (3s by default)

Example: Robot Framework

*** Tasks ***
Run Notepad
    Windows Run   notepad

Example: Python

from RPA.Windows import Windows
lib = Windows()

def run_notepad():
    lib.windows_run("notepad")

RPA.Windows

image/svg+xml