This is UltimateRPA Documentation
Multiple applications

In a single robotic process, the UltimateRPA robot can automate multiple applications. One robotic process, for example, can handle Internet Explorer, Excel and Adobe Reader. In this tutorial, you learn how to control multiple applications within a single robotic script.

Running multiple applications with the robot

The following example shows how to launch two applications RpaTableTest and RpaLoginTest in a single robotic script. You must start with importing urpa module in the file. To open an application use the function exec_app, and pass the application path as the argument. The application path may be absolute or relative to the script. It is important to disable auto close of the application using the application object method set_auto_close so that RpaTableTest is not closed when the script is run. The application object is returned by the function exec_app. Note: If you run the application RpaTableTest through PyScripter and disable auto close, you must then end it manually before rerunning the robot.

import urpa
def main():
app_table_test = urpa.exec_app("TutorialApps/RpaTableTest.exe")
app_table_test.set_auto_close(False)
app_login_test = urpa.exec_app("TutorialApps/RpaLoginTest.exe")

The input parameter for the function exec_app is a path to an app which is present relative to the script file directory. For instance, "TutorialApps/RpaTableTest.exe" assumes that the above script is placed in the main directory of UltimateRPA tools. If your script is saved elsewhere, remember to change the path in the above example.

ControlMultipleApplication_starting_two_apps.png
Figure 1 Two open applications

If the first application RpaTableTest is already running when you run the script (using ALT + F9), the second application RpaLoginTest launches and blinks on the desktop while RpaTableTest remains running.

Application closure options

You can force an application to close by invoking close method on the application object. For instance, in the above example if you need to force close the RpaTableTest then invoke method close on the application object app_table_test. Note: You can choose to force close an application at the end of the script when you are unsure of the auto close flag value set by set_auto_close method.

import urpa
def main():
app_table_test = urpa.exec_app("TutorialApps/RpaTableTest.exe")
app_table_test.set_auto_close(False)
app_login_test = urpa.exec_app("TutorialApps/RpaLoginTest.exe")
app_table_test.close()

If you run the above script (ALT + F9), and if RpaTableTest is already running, RpaLoginTest blinks on the desktop and RpaTableTest then also closes using the method close.

Repositioning and resizing the application window

To position and resize an application window you may use the resize_tp_window method of the application object. The first parameter to this method is the GUI element that identifies the application window. The second parameter is a tuple with values (left, top, right, bottom) that represent the application window position and size on the screen. The resize_tp_window method is helpful to position the window on the screen when there is a chance of application windows overlapping each other. For instance, in the above example the RpaTableTest window and RpaLoginTest windows may overlap each other depending on the sequence in which they were launched. You can use the method resize_tp_window to reposition both the windows to be visible when the script is run. In the following example the first parameter is "Login" for RpaLoginTest application and "RpaTableTest" for the RpaTableTest application. These parameters are the GUI element identifiers for both the application windows respectively. The following example also adds a delay using time.sleep() method at the end of the script to make the repositioning of the applications clear while the script is run.

import time
import urpa
def main():
app_login_test = urpa.exec_app("TutorialApps/RpaLoginTest.exe")
new_position = (1, 1, 400, 200)
app_login_test.resize_tp_window("Login", new_position)
app_table_test = urpa.exec_app("TutorialApps/RpaTableTest.exe")
new_position = (1, 200, 600, 600)
app_table_test.resize_tp_window("RpaTableTest", new_position)
time.sleep(3)
ControlMultipleApplication_apps_resized.png
Figure 2 Application positions changed

If you run the above script using (ALT + F9), RpaLoginTest window is moved to the upper left corner of the desktop, and the RpaTableTest window appears exactly under RpaLoginTest.

Since AppExcel and AppIE classes are derived from App class, all the examples and properties in the above examples also apply broadly to the AppExcel and AppIE objects returned by exec_excel_app and exec_ie_app respectively.

Initializing size of the application's TP (TopParent) window

While launching an application using the method exec_app you can specify the size of the TP app window. The second parameter of the exec_app method allows to specify options like "Maximize", "Minimize", "Normal" and "Hide". For instance, if you set the second parameter as "Maximize" the app window opens in maximized mode. The following example shows how to do open the RpaStartTest application window in maximized mode. Note: The application should support these standard operations to maximize, minimize, etc. for the second parameter to take effect.

import time
import urpa
def main():
app_test = urpa.exec_app("TutorialApps/RpaStartTest.exe", "Maximize")
time.sleep(3)

The TP or TopParent window is always the application's uppermost window. If, in Inspector, you move crosshair over any application, the application's TP window is always represented by the first direct descendant of the root of the tree that displays the process name and PID.

ControlMultipleApplication_inspector_top_parent.png
Figure 3 Selected TopParent in Inspector

Finding a running application

To find an application that is already running you may use the method find_first_app. The first parameter passed to this method is the unique name of the TP window title or the ClassName of the TP window of the application being sought. To find the unique name of the TP window use the tool Inspector. To find the TP unique name of RpaTableTest application run the Inspector. After running the Inspector, drag its crosshair over RpaTableTest. After releasing the crosshair, select the second row of "RpaTableTest[Window]" in the tree on the left-hand side of the Inspector. Subsequently, in the Name row of the Value column on the right-hand side of Inspector, the value of the title of the RpaTableTest TP window is displayed, and the value of the TP window's ClassName is displayed in the Class Name row of the Value column. To uniquely identify RpaTableTest, it is advisable to use the value of the title of the TP window "RpaTableTest". The find_first_app method returns the application object that can be used to manipulate the application for instance, closing it.

import urpa
def main():
app = urpa.find_first_app("RpaTableTest")
app.close()
RpaTableTest.png
Figure 4 RpaTableTest application

In the above example when the script is run using (Alt + F9), the application RpaTableTest is found and then closed if running.

Similar methods are available for finding the running Excel and ie apps. For Excel the method find_first_excel_app is used and for IE the method find_first_ie_app is used. Note: If you cannot find the unique identifier for an app to pass to the method find_first_app you may use the method open_app. This method searches for the application by PID (Process ID) and returns an application object if the app is already running.