Select chapter

3. Commands with Target

We mentioned in the chapter "A Brief Introduction of RPA" that one of the main features of RPA is that it is non-invasive. In other words, although RPA works with other software programs, it does not require them to provide a special interface. Instead, it directly interacts with the user interface of other software programs to simulate human interactions. However, there are often many input boxes and buttons that we can interact with in a given software interface. How does Laiye RPA know where and how we want to operate? The interface elements introduced in this chapter will solve this problem.

3.1 Interface Element Overview

If you have some programming experiences and know what a control is, then please forget this concept for now. Controls and interface elements have something in common, but they are not exactly the same, so we must try to avoid conceptual confusion.

Other than programmers, most people interact with the graphical interface of the operating system when using computers. Whether it is the commonly used Windows and Mac OSX or Linux, which is not well-known amongst non-programmers, they all have their own graphical interfaces. As web browsers became widely adopted, more and more graphical interfaces are displayed in a browser. These graphical interfaces can take on many shapes and forms, but when we click on them with our mouse, there is a small graphical component to register that we have clicked on something. We will call these graphical components interface elements.

For example, the figure below is a commonly seen window on the Windows operating system, as well as a typical graphical user interface. What are the interface elements in this window?

FIGURE 26.png
Figure 26: Common window on Windows

First of all, there are various options in the menu bar above, such as "File", "Home", "Share", and "View", and these are all interface elements. The icons and the text in the toolbar below, such as "copy" and "paste", are also interface elements. Likewise, the "Quick access", "Desktop”, and "Download" in the navigation bar to the left are all interface elements. Each file displayed in the main area of the window (highlighted by the red box in Figure 28) is also an interface element.

Notice how interface elements can also contain one another. For example, the area of the window highlighted by the red box is a large interface element, and it contains the interface element representing each file inside it.

In Laiye RPA, the role of the interface element is to serve as the target in commands with targets (i.e., commands that require a target).

As mentioned earlier, Laiye RPA provides a large number of built-in commands, which you can find in the command area. Among them, the most basic ones are as shown in Figure 27.

FIGURE 27.png
Figure 27: The most basic commands

Among them, all commands under the Interface Element and Text categories require targets. Likewise, commands under the Mouse and Keyboard categories that contain the word "target" also require targets. These commands are highlighted by the red boxes in Figure 28.

FIGURE 28.png
Figure 28: Command with target

Commands with target specify an interface element as a property. When you run this command, it will first check whether this interface element exists. If it exists, the command will perform its specific operation on it. For example, if the specified interface element is a button, then the command Click Target will click this button. If the interface element does not exist, the command will search for the interface element repeatedly until some time limit is reached (this is known as timeout, and the specific time limit can be set as a property). An error, in turn, terminates the process.

Conversely, commands without target do not take an interface element as a property. For example, the Simulate Click command has no target. When you run this command, it will click where the mouse currently is. As another example, the Simulate Key command also has no target. When running, it will simulate a key operation where the keyboard is currently focused on.

Whenever possible, you should always prefer using commands with target, because they are much more accurate. Only when you cannot specify the target as an interface element should you use commands without target as the second best choice.

Therefore, selecting a target accurately is critical when using Laiye RPA. As long as the target is selected correctly, simulating an operation is relatively simple. Here is a detailed description of how to select a target.

3.2 Select Target

Laiye RPA provides fully automatic methods to select a target. Let's consider the Click Target command in the Mouse category as an example.

Suppose we want to execute a very simple process, which only has one step: click the start menu button of Windows (the default position is in the lower left corner of your screen). First, create a new process and open the only Block in it. Then, find the Click Target command in the Visual View and insert it into the assembly area by dragging and dropping or double-clicking the command. You should already be familiar with these steps. If you are not, please go back and read Chapter 2, "Basic Concepts."

Now, there should be a command in the assembly area. Note that there is a button on this command with the text "Find Target" next to a target icon, like the one in Figure 29.

FIGURE 29.png
Figure 29: Click Target command and the "Find Target" button

Click this button. The Laiye Creator interface will be temporarily hidden, and a translucent mask with red border and blue background appears. This is the target selector, which shows you the available interface elements that you may select as the target. The target selector follows wherever the mouse moves. When we left-click on an interface element, the target selector disappears and the Laiye RPA interface reappears. The interface element covered by the target selector when we left-click is the target we have selected. As mentioned earlier, interface elements may be nested, and the mouse may be hovering over multiple interface elements at the same time. In this case, the target selector will automatically choose the interface element you most likely need and cover it. Therefore, before left-clicking to confirm your selection, please move your mouse patiently until the target selector perfectly covers the interface element you need.

Let's have a try. Use the target selector to cover the start menu button, and makes sure the selector covers it perfectly. When the mask changes to the state shown in Figure 30, left-click to confirm the selection. Note that the figure below is what it looks like in the Windows 10. If you're using a different version of Windows, what you see will be different, but the idea remains the same.

FIGURE 30.jpg
Figure 30: Use the "Target Selector" to select the start menu button

Once selected, Laiye Creator reappears, and the Find Target button you just pressed now looks like a thumbnail of the target interface element you selected. This thumbnail helps you remember which target you just selected and has no impact on how the command executes. Moreover, this thumbnail is actually a button. If you click on the thumbnail, it will take you to the exact same interface that you see when you click on the Find Target button. If the previously selected target is not what you need, or if you accidentally selected the wrong target, just press this button and try again.

Notice that every command with target has a property named Target. When we have not yet selected a target, the value of this property is a pair of curly brackets "{}", as shown in the left image in Figure 31. Note that because no target is selected, something will definitely go wrong if we try to run the command. After we have selected a target, the Target property is populated with a complicated value, but it is still surrounded by a pair of curly brackets, as shown in the right image of Figure 31.

FIGURE 31.png
Figure 31: The value of the Target property

The value should look something like this:


Once you have learned Laiye RPA's programming language, BotScript, later on, you will know that the value shown here is actually a "dictionary" data type in BotScript. For now, don’t worry about these details. Just know that this is a special piece of data that specifies the interface elements you have selected. Using this data, Laiye RPA can reselect the target consistently.

If you have developed Windows applications before (if you haven't, just skip to the next section), you know that there are actually many development frameworks for applications on Windows, including SDK, MFC, WTL, WinForm, WPF, QT, Java, etc. If you count web applications that run in IE and Chrome, there are even more types. These frameworks all provide the capability of searching interface elements within its applications. From a technical standpoint, Laiye RPA is simply referencing the interface element searching APIs provided by these frameworks. This might not seem complicated, but the methods to call all these APIs are different from each other, and even a skilled developer would struggle to learn all these interfaces in a short time, let alone users not familiar with software development.

However, if you use Laiye RPA, all of these different frameworks are all abstracted as the same interface elements, and you can search and operate on them in the same way. For example, a button in an MFC program and a button in Chrome may seem like they are all just buttons, but the technical difference in simulating clicking on these two buttons is huge. In Laiye RPA, you don't need to care about these differences at all, because Laiye RPA will handle the details for us. Therefore, this is how Laiye RPA achieves and balances the three indicators of an RPA platform: powerful, simple, and fast.

3.3 Edit Target

We have learned in the previous section that the target selector in Laiye RPA works automatically. As long as we move the mouse to the interface element that we want as the target, the target selector will perfectly mask over the needed interface element and generate a piece of data to describe the element, which allows Laiye RPA to find the target again during runtime.

Naturally, any automatic tools will fail from time to time. When using target selectors, there are some common problems:

  • No matter how we move the mouse, we can't make the mask perfectly cover the intended interface element. A common situation is that the mask is covering the whole window, instead of selecting the element you need, which might be smaller or inside that window.

  • The mask can perfectly cover the interface elements, but when you try to find the target during runtime using the generated data, one of the following occurs:

- Incorrect selection: the interface element can be found, but it is not the one we originally selected.

- Missed selection: the interface element existed at the time of selection, but now it cannot be found.

We will address the first scenario, i.e., when the target cannot be covered, in detail in the next chapter. Here, we will focus on the second scenario, i.e., when the target can be perfectly covered, but Laiye RPA selects incorrectly or fails to select the target in runtime. As we mentioned in the previous section, Laiye RPA generates a piece of data similar to the one below to describe a selected target.


Laiye RPA finds the target according to this piece of data when running the process. Therefore, when Laiye RPA misses or incorrectly selects a target, something is wrong with this data, and we need to modify it.

Locate the Target property of the command, where the piece of data is displayed in the corresponding input box. It is possible to directly edit the content of the field using the input box, but the box is too small for efficient editing. Therefore, we recommend you click on the button to the right of the input box, shown in red in Figure 32.

FIGURE 32.png
Figure 32: Modify target

After you click the button, a Target Editor window pops up. The image on the top of the window is a thumbnail, which shows the general appearance of the target interface element. Once again, this is just for your own reference, and Laiye RPA will not use it when running the process. Right below the thumb is the Control Filter, which displays the piece of data you saw earlier as a tree structure (Figure 33).

FIGURE 33.png
Figure 33: Target Editor

This tree structure displays the features of the interface element chosen by the target selector earlier. Each item is a feature, and they have been automatically selected by Laiye RPA to describe the element. During runtime, Laiye RPA only selects an interface element if it contains all these features. Moreover, because the interface elements are nested with each other, Laiye RPA will not only record the features of the target interface element, but also the features of parent interface elements of the target. Therefore, for an element to be selected, the features of each specified level must be satisfied.

Take the start menu button of Windows in the above figure as an example. The line 0: Object and the entries underneath it represent the features of the interface element that contains the start menu button (the Windows taskbar), while the line 1: Object and the entries underneath it represent the features of the start menu button itself. During runtime, Laiye RPA will search level by level. It will first find the Windows taskbar at the first level; then it will search for the start menu button within the children elements of the taskbar.

Such strict feature matching naturally leads to situations when Laiye RPA is unable to find an element that fits. In this example, Windows assigns start menu a "title," with the value "start" (the title is usually hidden from users, but it exists underneath the hood). Laiye RPA takes this title as part of its feature, because, in general, the title of the button does not change. However, if one day the title of this button changes, Laiye RPA would fail to find the button.

In this case, we’ll need to modify our feature matching process. We can see that there is a check box before every feature that is checked by default. Uncheck the "title" field, and Laiye RPA will no longer use this feature when searching for the target interface element. This way, even if the title changes, the target interface element can still be found.

However, if too many features are removed, though you are less likely to miss the intended target, you are more likely to end up with an incorrect selection. For example, if you uncheck both cls: "Start" and title: "start", then any interface element under the Windows taskbar (selected by 0: Object) can meet the condition, and Laiye RPA will likely select the wrong element.

Therefore, if the interface elements are complicated, or if their features often change, then it takes some practice and skill to edit the target to accurately select the intended element. Unfortunately, there are no specific rules in this regard, so you need to learn from experience. Here are several general guidelines to help you get started:

  • You may be unfamiliar with some feature names for the time being, such as cls, aaname, etc. Don’t worry about them.

  • Make good use of the wildcard symbol *, which matches anything. For example, if there is an interface element that has a feature title with value "Name: James". The actual name “James” might change, but the first part of the title “Name: “ will remain constant. Therefore, you can use title: "Name: *" as a feature, rather than simply removing it.

  • Be conservative when removing features. Although removing features can reduce missed selections, your feature set could quickly become too general to avoid selecting the wrong elements. When the process is running, missed selections are generally easier to debug, while incorrect selections may not be found immediately.

Expanding on the last point, we note that when Laiye RPA is running a process, most commands with target (except for commands like Decide If Target Exists) throw an exception when the described target element is not found. Unless the exception is handled by a Try…Catch clause (more on this later), it would terminate the process immediately and report the error to you, which makes it easy to notice. On the other hand, if Laiye RPA selects an incorrect target, it does not know that, so it will continue to run, which silently suppresses the error and makes it hard to notice.

Lastly, the same interface elements may have different features on different operating systems and different browsers. Especially for Internet Explorer and Chrome, the same elements on the same page usually have drastically different features. For example, selecting the search bar on in IE and Chrome generates massively different feature sets (see Figure 34).

FIGURE 34.png
Figure 34: The features of the same target are different on IE and Chrome browsers

Therefore, when using the Laiye RPA to create a process to be run on other computers, please try to ensure that the development and production environments are consistent (i.e., same operating system, same browser, etc.) in order to reduce unnecessary runtime errors.

3.4 Interface Element Operation

The list of built-in commands interacting with interface elements is given in Figure 35.

FIGURE 35.png
Figure 35: The list of interface element operations

Don’t be overwhelmed by how long this list is. There is no need to learn all these commands one by one. By learning some of the commands and understanding the design of Laiye RPA, you can extrapolate problem solving principles that help you know what commands and what even properties for these commands to use when you have a certain functionality in mind.

As we have learned, operations on interface elements are executed through commands, and properties are an indispensable part of the command. In fact, a command is complete only when its key properties are clearly specified. Generally speaking, a command consists of the following parts: Command = (do what) + (to what) + (with what) + to (get what).

Do what refers to operation itself. In general, the types of operations that can be performed on a target depends on the type of the target. Once you have determined the target, you know what operations you can do to it. For example, you can use click on a button, while you generally can’t click on texts. In a similar vein, there are special operations to checkboxes, including one determining whether a box is checked and one setting the status of a checkbox. There are also some common operations that are available in almost all interface elements, such as obtaining the size, position, and text of an interface element.

To what refers to the object, or target, of the command’s operation. For interface elements, targets can be dropdowns, checkboxes, textboxes, and more. We have already learned how to select an interface element using Laiye RPA’s target selector.

With what refers to additional modifiers the user needs to provide when invoking this command. This also depends on the type of the target. For example, the user needs to enter a Boolean value (true or false) when setting the status of a checkbox. However, there are some commands that can be executed without any additional information from the user, such as Get Element Text. As long as the user sets the target of this command, the command can get the text of the element without any more information. In this respect, "with what" is similar to parameters in programming. A command that does not require additional information is just like a function that takes no parameter.

Get what refers to the result returned by the command. For example, invoking the command Get Element Text returns a string whose value is the text of the element. Likewise, invoking the command Get Element Selection against a set of checkboxes returns an array of Boolean values (each value corresponds to one checkbox).

In essence, Laiye RPA simulates real human operation to computers. It encapsulates each operation into a command, and the key properties of these commands are determined by its target.

Let us consider a test form to demonstrate how to operate interface elements. This interface includes text labels, radio boxes, checkboxes, single-line textboxes, multi-line text boxes, list boxes, dropdowns, etc., which are all common interface elements in forms.

FIGURE 36.png
Figure 36: Test form

3.4.1 Check If Element Exists

As the name implies, the command Check If Element Exists determines if a specific interface element exists in the current screen and stores the result in a variable. When the interface element exists, the command returns true; otherwise it returns false.

If you need to check whether a desired interface has appeared on the screen, you can check if a key element on that interface exists using this command. If this element exists, it indicates that the interface appears; otherwise it means that the interface does not exist.

For example, let's check whether the submit button on the test form exists.

  1. Drag and drop the Check If Element Exists command to the Visual View, as shown in Figure 37.

    FIGURE 37.png
    Figure 37: Check If Element Exists

  2. Click the Find Target button on Check If Element Exists, switch to the test form, and hover your mouse over the submit button, so that the red edge and blue mask perfectly covers the submit button. Left-click to confirm your selection.

  3. The result of the Check If Element Exists command is saved in the variable bRet, as shown in Figure 37. We can use an conditional to check whether the result is true or false. True indicates that the element is found, and false indicates that the element is not found.

3.4.2 Set/Get Element Ticked

The command Set/Get Element Ticked allows you to operate form elements, specifically radio boxes and checkboxes, automatically. Let's use the test form again for demonstration.

  1. Drag and drop the Set Element Ticked command to the assembly area. Use the Search Target button to select the options "Music" and "Sport" under the "Hobby" section. Take care to select the corresponding checkboxes, not the texts "Music" and "Sport" themselves.

  2. Drag and drop the Get Element Ticked command to the assembly area. Use the Search Target button to select the options "Music" and "Sport" under the "Hobby" section.

  3. Use the Output command to display the values of bRet and bRet2, which correspond to whether the selected checkboxes are checked.

  4. Run the process (see Figure 38). You should see "True" twice, which indicates that both elements are checked.

    FIGURE 38.png
    Figure 38 : The command and result of setting/getting element ticked

  5. On the testing page, we can see that the checkboxes for "Music" and "Sport" are now checked. We have successfully filled the form using these two commands.

3.5 Install Extension

When selecting a target with a mask, we often run into situations where the mask only ever covers an entire window, and no matter what you do, the mask refuses to select the interface elements within the window. As shown in Figure 39, the mask only selects the whole Chrome tab, but it cannot select the input boxes and buttons inside the tab.

FIGURE 39.png
Figure 39: Trouble selecting specific elements in a Chrome tab

There are two possible reasons for this situation. One possibility is that there is no possible way to select this interface element (more on this later). The other possibility is that the interface is actually selectable, but it requires additional support from Laiye RPA. At the time of writing, Laiye RPA provides extensions for Chrome, Firefox, and Java programs. Installing the corresponding extensions allows us to select page elements in Chrome, page elements in Firebox, and Java interface elements like Swing, AWT, JNPL, Applet, etc.

Let's take the Chrome browser as an example to see how we can install these extensions.

3.5.1 Chrome Browser

Chrome requires us to both install and enable the Laiye RPA extension to properly select elements inside a webpage. After you have installed the extension, you will see the icon in Figure 40, located to the right of the address bar. When you hover over the icon, a tooltip with the text "Laiye RPA Native Message Plugin" should appear.

FIGURE 40.png
Figure 40: Laiye RPA extension icon on Chrome browser

If you have not installed the extension, follow these steps to install it:

  1. Close Chrome.

  2. Open any process in Laiye RPA Creator. Select "Help" -> "Install Extension" in the menu, and then select "Chrome Extension".

  3. Open Chrome. The browser should prompt you that a new extension has been added (Figure 41). Click "Enable Extension”. You should be all set.

    FIGURE 41.png
    Figure 41: Chrome browser prompts you that a new extension has been added

  4. If you are still experiencing difficulties selecting Chrome interface elements, please follow Figure 42 to enable Laiye RPA Native Message Plugin.

    FIGURE 42.png
    Figure 42: Extension management of Chrome browser