This is UltimateRPA Documentation
First robotization

First script with UltimateRPA

A robot controls applications in the same way as a user. Robot commands are written in Python 3.7 (until version 4.5 it was Python 2.7). This tutorial assumes at least a basic understanding of Python language.

We demonstrate how to create your first robotic script in UltimateRPA. In the directory where you unpacked UltimateRPA, run PyScripter.exe. This opens the PyScripter development environment where you create the new file. In the File menu, select New and then New Python module, or use the keyboard shortcut (CTRL + N), and save the file as start.py (CTRL + S).

Import UltimateRPA

First, add the UltimateRPA module to the script with the import command, enabling you to use the UltimateRPA robot.

import urpa

Main and application run functions

Define a function called main. This function is crucial and must be included in every script that you want to run. Inside this function, invoke the function exec_app from the urpa module that runs an application to be used. The parameter to the function exec_app is a string with a path to the application that we want to run. The path should be an absolute path or a path relative to the script. The following example uses RpaStartTest application for your first script.

import urpa
def main():
urpa.exec_app("TutorialApps/RpaStartTest.exe")

The path to an app "TutorialApps/RpaStartTest.exe" is relative to the script file directory. The app path in the above code assumes that the script is placed in the main directory of UltimateRPA tools. If your script is saved elsewhere, remember to change the path.

Now run the script using the robot. In the upper PyScripter menu, select Run and then External Run, or use the keyboard shortcut (ALT + F9).

FirstRobotization_RpaStartTest_blink.gif
Figure 1 RpaStartTest application blinking

As you can see, the application runs and then immediately closes. This is because the default setting tells the robot to exit all the applications it has run when the script ends. This behavior can be modified by setting Auto Close property to False using the method set_auto_close of the app object. The function exec_app returns the app object. Setting Auto Close to False commands the robot not to shut down the application at the end of the script.

import urpa
def main():
app = urpa.exec_app("TutorialApps/RpaStartTest.exe")
app.set_auto_close(False)

Now when the script is run (ALT + F9), the application remains running even after the script has ended, enabling you to view it.

RpaStartTest.png
Figure 2 RpaStartTest application

The application is straightforward and contains only one unique element, i.e. the Start button. This is activated in subsequent steps via the robot. As only one application instance can be run at a time in PyScript, the application must be closed by the user before another can be run.

Finding the Start button

In order to be able to perform an action on a GUI object, you must first identify and find it. The way in which objects can be identified is explained in more detail in the chapter Inspector. All you need to know at the moment is that the button can be identified using the "Start" string. Invoke the app object method find_first with the "Start" attribute, which returns the Start button object – you can use to perform user interactions with.

import urpa
def main():
app = urpa.exec_app("TutorialApps/RpaStartTest.exe")
app.set_auto_close(False)
app.find_first("Start")

Running a script in debug mode

You can run the robot in debugging mode, which is used for script development and tuning (debugging). When the script is run, this mode always marks the object found with a green frame. Set the debug mode using function set_debug_mode in the urpa module to True to observe this behavior. After setting the debug mode to true all actions executed run in debugging mode.

import urpa
def main():
app = urpa.exec_app("TutorialApps/RpaStartTest.exe")
app.set_auto_close(False)
app.find_first("Start")

Run the above robot script, and a green frame is drawn around the Start button. This means you have found what you were looking for, and you can use this GUI object to trigger actions like clicks.

FirstRobotization_RpaStartTest_debug_mode.gif
Figure 3 Debugging mode highlighting GUI element

The debugging mode also inserts a short pause between each robot step to allow you to register what is happening in the application.

Clicking the Start button

Clicking a button is easy. Invoke the method send_mouse_click for the element object retrieved. This method ensures that the cursor is moved over the center of the object, and performs a click action.

import urpa
def main():
app = urpa.exec_app("TutorialApps/RpaStartTest.exe")
app.set_auto_close(False)
app.find_first("Start").send_mouse_click()

Rerun the script. The robot finds the Start button and clicks on it. This gives you access to two text fields in the application.

FirstRobotization_RpaStartTest_mouse_click.gif
Figure 4 Clicking Start button reveals two text fields

Filling in a text field

Now fill in the string "UltimateRPA" in the text input field containing the@ character. Just as when you made the click action with the Start button, you first need to find the text field in the application. Different ways to search for an element are discussed in the separate chapter. For now, keep using the method find_first that you used to find the Start button. After the input field object has been found, you can use the method send_text on it. Pass the "UltimateRPA" string to this method as an argument. This method inserts the string into the text input field.

import urpa
def main():
app = urpa.exec_app("TutorialApps/RpaStartTest.exe")
app.set_auto_close(False)
app.find_first("Start").send_mouse_click()
app.find_first("@").send_text("UltimateRPA")

Run the robot. You can see that the text has been inserted into the field, but the @ character has been left and you want to remove it.

FirstRobotization_RpaStartTest_send_text.gif
Figure 5 Inserting text in edit field

Pressing the Delete button

The robot performs a delete action just as a regular user would delete text by pressing the Delete key. First, save the text field object sought in the edit box variable. Then use the send_key method for the edit box object. This method is invoked with the argument "DEL" and ensures that the Delete key is pressed when the text field has focus. Then use the send_text method with the "UltimateRPA" string to input the text in the edit box.

import urpa
def main():
app = urpa.exec_app("TutorialApps/RpaStartTest.exe")
app.set_auto_close(False)
app.find_first("Start").send_mouse_click()
editbox = app.find_first("@")
editbox.send_key("DEL")
editbox.send_text("UltimateRPA")
FirstRobotization_RpaStartTest_send_key.gif
Figure 6 Pressing DEL key

This was a demonstration of the essential use of the UltimateRPA robot. This concept is discussed in more detail in other chapters.