Windows locators

For a quick overview of what this feature offers, feel free to check out these short and detailed youtube videos:

Windows locators

Open the classic calculator application and we will automate a simple addition flow:

Open the Inspector

  • Click the Robocorp icon in the Activity Bar.
  • From the Package Resources panel, expand the Windows menu and select New Windows Locator ....

Create a new automation flow

A Robocorop Inspector tab will appear inside VS Code:

Browser locator modal

From the Select Application drop-down select the Calculator application.

Once an application is selected, the element tree is displayed.

Let us automate the simple flow illustrated in the gif above, 5 + 7 = 12. First click on 5 and select from the right-hand side panel the desired Element Attributes by which you want your element to be identified. Select only the Name attribute as we don't see any other elements with 5 in the application and press Test Rule to check whether your locator is unique or not.

Looks like the calculator display can also be identified in this case by the attribute name : 5 so this selctor is not unique. Add the attribute Class as well to your selection and test the rule now.

Once we are are sure our element is uniquely identified, press Add rule. You can preview the generated code and press Push Action to save the click action on our button.

You can view the saved actions in the Actions tab:

Go back to App Explorer tab, press Start picking and select the rest of the buttons needed for our flow: +, 7, = using the steps above.

Press Clear Rules in between elements if you do not want to chain them. Once you add a rule, the identified element can be used as the starting point for the next element, becomeing a parent element inside which the next element is searched.

Let's also check what number is displayed, so following the steps above, select the display of the calculator. After testing the rule and adding it, change the action performed on the element to get_text() to get the value of that field.

Push the action to have the final code. Let us copy the script and add it to our python file:

You have to import the windows library in your python file: from robocorp import windows

And add the library import to conda.yaml as well: - robocorp-windows==1.0.1 Please make sure you add the latest version of the library.

from robocorp.tasks import task from robocorp import windows @task def minimal_task(): app = windows.find_window('regex:.*Calculator') app.find('class:"Button" and name:"5"').click() app.find('class:"Button" and name:"Add"').click() app.find('class:"Button" and name:"7"').click() app.find('class:"Button" name:"Equals"').click() result = app.find('name:"Result"').get_text() print(result)
Last edit: March 19, 2024