This is UltimateRPA Documentation
Condition factory class

Creation of GUI element search conditions

An instance of the class Condition is used as a parameter in methods to find a GUI element in a robotic application, e.g., in the find_first method. Activity can then be simulated over the retrieved GUI elements with a mouse or keyboard. An instance of the class Condition is created using the class ConditionFactory. Each instance of the class Condition contains the internal methods for example, name, value, size; these methods represent GUI element search conditions.

Running the test application RpaTableTest

In the UltimateRPA Tools directory, run PyScripter.exe to open the PyScripter development environment. Create a new file or robotic script. In the File menu, select New and then New Python module, or use the keyboard shortcut (CTRL + N), and save the file as condition_factory.py (CTRL + S). First, add the UltimateRPA module to the robotic script and define an instance of the class ConditionFactory cf. Next, define the main function. Run the RpaTableTest application here via the function exec_app. To highlight objects found in the processing of the robotic script, enable the debugging mode using the function set_debug_mode.

RpaTableTest.png
Figure 1 RpaTableTest application
import urpa
def main():
app = urpa.exec_app("TutorialApps/RpaTableTest.exe")

The path to an app "TutorialApps/RpaTableTest.exe" is relative from the script file directory and assumes script being placed in the main directory of UltimateRPA tools. If your script is saved elsewhere, remember to change the path.

Run the script. In the PyScripter menu, select Run and then External Run, or use the keyboard shortcut (ALT + F9). RpaTableTest runs and closes. Specifically, it blinks on the desktop.

Creating a simple condition

Manually run Inspector and RpaTableTest. In Inspector's Search function selection field, set the value (none). Drag Inspector's crosshair over RpaTableTest, specifically over the Delete selected lines button, and release the left mouse button. The values in the Value column are updated in Inspector. In Inspector, activate the checkbox in the line with Name-Name and Value-Delete selected lines. After the checkbox is activated, an expression is created for the GUI element search in the Expression edit box at the bottom of the Inspector dialog. Transfer the expression, representing a new instance of the object Condition, to the robotic script via the system clipboard. In the robotic script, define the new instance of the class Condition condition_delete. This new instance of the class can then be used in a parameter of the method find_first to find the GUI element element_delete, representing the Delete selected lines button in RpaTableTest.

Inspector.png
Figure 2 Inspector application
import urpa
def main():
app = urpa.exec_app("TutorialApps/RpaTableTest.exe")
condition_delete = cf.name("Delete selected lines")
element_delete = app.find_first(condition_delete)
ConditionFactory_delete_lines_selected.png
Figure 3 Highlighted button "Delete selected lines"

Run the script. RpaTableTest runs, the Delete selected lines button is highlighted, and the application closes. With the element_delete object thus created, a mouse activity simulation, for example, can then be defined – see chapter Robotic Interaction.

Creating a more complex condition

A more complex condition for finding a GUI element may comprise, for example, the requirement to find all GUI elements that, in the Name attribute, have a five-place value with "a" as the third character. To create this condition, it is first necessary to create a regular expression to ensure that the above conditions are met. Rules for creating and evaluating a regular expression are described as part of the method regexp. A regular expression fulfilling the above conditions might look like this: "^..a..$". After a regular expression has been created, you can define, in the robotic script, the new object instance Condition condition_regular. This new instance of the class Condition can then be used in a parameter of the method find_all to find the set of GUI elements elements_delete meeting the condition_regular condition.

ConditionFactory_a_strings_selected.png
Figure 4 Finding strings that meet a condition
import urpa
def main():
app = urpa.exec_app("TutorialApps/RpaTableTest.exe")
condition_regular = cf.name(cf.regexp("^..a..$"))
elements_regular = app.find_all(condition_regular)

Run the script. RpaTableTest is run, and GUI elements meeting the condition_regular condition, i.e. GUI elements with the names Small, Black and Brand, are highlighted. RpaTableTest then closes.

Condition in a Java application

The robot can also service elements in Java applications. Let’s try this on RpaLoginTest.jar, which you can find among the Tutorial Apps. Run RpaLoginTest.jar via exec_app. Transfer the following command to the function as a parameter: java -jar, complemented by the path to the app you have run. Create the condition using Inspector. The first condition is the java method. Then define further element properties using methods from JavaCondition. Some methods are the same with Condition, such as name, and some are unique to Java apps, such as push_button.

import urpa
def main():
app = urpa.exec_app("java -jar TutorialApps/RpaLoginTest.jar")
condition_java = cf.java().name("Login").push_button()
elements = app.find_first(condition_java)
ConditionFactory_java.png
Figure 5 Finding a button in a Java app

The script runs the Java application RpaLoginTest.jar and finds the Login button. Because the debugging mode is enabled, the button is framed in purple.