Skip to main content

Network and System Operation

Network Operation

HTTP Operation

Almost all URLs need to be prefixed with http://. HTTP is an abbreviation of Hyper Text Transfer Protocol (Hyper Text Transfer Protocol), which refers to a hypertext transfer and communication protocol between a local browser and a web server. In other words, when we use a browser to access a website, we are essentially dealing with a remote web server through the HTTP protocol.

In fact, it does not have to be a browser. As long as it follows the standard of the HTTP protocol, other applications can also communicate with the web server. This is great! This shows that some webpage automation operations introduced in the previous chapter can be operated directly through the HTTP protocol instead of the browser. This opens up a new idea for the automation of network operations.

There are two main types of HTTP requests that are used more frequently: HTTP GET and HTTP POST.Let's take a look at how to implement these two types of requests in Laiye RPA. The first is the HTTP GET request. In the "HTTP" directory of the "network" in the command center, select and insert a "get" command, which will create an HTTP GET request that points to a specific URL. This command has four attributes, as shown in the figure below.

**Figure 35: Get to get data**

The "link address" attribute indicates the URL of the HTTP request, and the "form data" attribute is a string in JSON format, indicating the data to be sent for this HTTP request. There are two sets of key-value pairs, namely "user" and "username", "password" and "12345678", as shown below.

{
"user": "username",
"password": "12345678"
}

The "timeout" attribute specifies the timeout time of the HTTP request. If no data is returned after this time, the HTTP request is considered to have failed. The "output to" attribute fills in a variable name that will hold the result of the HTTP request, which is also a JSON-formatted string, as shown below. If you need to process the returned result, you can parse the JSON string based on the format of the returned result.

{
"args": {
"password": "12345678",
"user": "username"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.21.0"
},
"origin": "49.94.16.174, 49.94.16.174",
"url": "https://httpbin.org/get?user=username&password=12345678"
}

In addition to the normal GET request, the HTTP GET request can also download files through the HTTP GET request. This function is realized by the "get download file" command. This command has five attributes. The meaning of the four attributes "link address", "form data", "timeout", and "output to" is the same as the four attributes of the previous "get data" command, and the other one "file path" attribute fills in the save path of the downloaded file.

**Figure 36: Get download file**

Let's take a look at how to implement HTTP POST request in Laiye RPA. In the "HTTP" directory of the "Network" in the command center, select and insert a "post submission form" command, which will create an HTTP POST request that points to a specific URL. This command has four attributes, as shown in the figure below.

**Figure 37: Post submission form**

The meanings of the attributes of "link address", "form data", "timeout time", and "output to" are the same as those of the "get" command. It should be noted that the "form data" sent by the HTTP GET request is related to the requested URL, and it needs to be carefully checked with the relevant business personnel. The key-value pairs of the "form data" are carefully filled in correctly. Similarly, the result returned by the HTTP POST request is also a string in JSON format, as shown below. If you need to process the returned result, you can parse this JSON string according to the format of the returned result.

{
"args": {},
"data": "",
"files": {},
"form": {
"custname": "yzj",
"custtel": "123456"
},
"headers": {
……
},
"json": null,
"origin": "49.94.16.174, 49.94.16.174",
"url": "https://httpbin.org/post"
}

Mail Operation

In the automation of enterprise business processes, the automatic sending and receiving of emails is a very important part. In addition to automating the operation of the mail client or automatically logging in to the mailbox through a browser, Laiye RPA also provides commands to directly send and receive mail through the SMTP and POP3 protocols.

Just like using Gmail or Outlook to send and receive mail, before using SMTP and POP3 protocols to send and receive mail directly, you must log in to the mailbox to adjust some settings. Here we will use the QQ mailbox as an example. Open the browser, log in to the QQ mailbox, click the "Settings" button and then click the "Account" tab, find "POP3/IMAP/SMTP/Exchange/CardDAV/CardDAV service", click "On" in the "Open Service: POP3/SMTP Service" (the service is turned off by default). At this time, the QQ email system will generate a password and save it. This password will be used in subsequent email receiving and sending operations instead of your original mailbox password.

**Figure 38: QQ mailbox opens POP and SMTP**

Then click "how to use Foxmail and other software to send and receive mail?". As shown below, this help document contains the key settings of QQ mailbox: POP server address is pop.qq.com, port number is 995, SSL is "Yes"; SMTP server address is stmp.qq.com, port number is 465, SSL is "yes". This information will be used in subsequent Laiye RPA mail commands.

**Figure 39: QQ mailbox setting information**

Let's take a look at the command to receive mail, the first step to connect to the mailbox. In the "SMTP/POP" directory of the "network" in the command center, select and insert a "connect mailbox" command, which will use the POP protocol to connect to the specified mailbox and support subsequent operations for receiving mail.

**Figure 40: Connect mailbox**

The command has the following attributes: fill in the POP server address of the mailbox in the "server address" attribute, fill in the POP protocol port number in the "server port" attribute, and select "Yes" in the "SSL encryption" attribute. These three settings have been obtained from the setting of QQ mailbox in the previous step, where the server address is pop.qq.com and the port number is 995. Fill in the mailbox account that needs to receive mail in the "mailbox account" attribute, fill in the email account password in the "login password" attribute, and the password has been generated in QQ email in the previous step. Then, fill in "POP3" in the "use protocol" attribute by default and fill in the variable name objMail in the "output to" attribute. This variable will save the mailbox object obtained after connecting to the mailbox, and use this mailbox object for subsequent commands such as reading the mail title, the body of the mail, and downloading the mail attachments.

After successfully connecting to the mailbox, you can receive the mail next. Some of the mail collection operations supported in Laiye RPA are: get the mail title, get the mail body, get the mail sender, get the mail address, get the mail time, and save the attachment.

In the "SMTP/POP" directory of the "network" in the command center, select and insert a "get email header" command, which will get the mail header. This command has several attributes. In the "operation object" attribute, fill in objMail, which was obtained in the "connect mailbox" command. Then, fill in which mail we need to read in the "mail serial number". Here it contains "1", which means to read the first mail (the most recent mail). You can iterate through the mail in the mailbox by increasing the "mail serial number". Fill in the name of a variable in "output to" attribute. The variable holds the result of the "get message header" command or the text information for the message header.

**Figure 41: Get email header**

Several other mail collection commands, such as "get mail body", "get mail sender", "get mail address", and "get mail time", are similar to the "get mail header" command. Most of their attributes are the same, with the exception of getting message information. However, the "save attachment" command is different from the other five commands. There is one less "output to" attribute and one more "save address" attribute. The "save attachment" command does not save the attachment to "output to" variable, but instead stores the attachment directly to the file address filled in the "save address" attribute.

**Figure 42: Save attachment**

In addition to receiving emails, Laiye RPA also supports sending emails. In the "SMTP/POP" directory of the "network" in the command center, select and insert a "send mail" command, which will use the SMTP protocol to send an email to the specified mailbox.

**Figure 43: Send email**

The command has several attributes. Fill in the SMTP server address of the mailbox in the "SMTP server" attribute, fill in the SMTP protocol port number in the "server port" attribute, and select "Yes" in the "SSL encryption" attribute. These three settings were obtained in the previous step of QQ mailbox settings, where the server address is smtp.qq.com, and port number is 465. Fill in the mailbox account that needs to be logged in in the "mailbox account" attribute, fill in the email account password in "login password" attribute, and the password in QQ email has been generated in the previous step. Fill in the "mailbox" attribute with the other party's mailbox account and the subject of the message to be sent. Then, enter the body of the message to be sent. The "Email attachment" attribute should contain the address of the attachment file to be sent. Finally, the "output to" attribute returns whether the mail sending operation was successful: true on success, or false on failure.

System Operation

System Commands

Laiye RPA provides some practical system commands, such as playing sounds, reading and setting environment variables, executing command lines and PowerShell, obtaining system and user folder paths, etc. These practical system commands can be used in conjunction with other commands to achieve unexpectedly good results. Under "system operation" in the command center, select and insert a "play sound" command that plays the sound file with the specified file path. There is only one attribute of this command: "file path" attribute, which filled in the complete file path of the sound to be played. Currently, Laiye RPA only supports sound playback in wav format.

**Figure 44: Playing sound**

In the "system" directory of "system operation" in the command center, select and insert a "read environment variable" command, which can read the environment variables of the Windows operating system. There are two attributes of this command. In the "environment variable" attribute, fill in the name of the environment variable, and in the "output to" attribute, fill in a variable name. This variable will save the value of the environment variable read out. It should be noted that the "read environment variable" command can only read one variable at a time. If you need to read the values of multiple environment variables, you can call this command multiple times. In addition, the text format of the read environment variables is completely consistent with the text format of the environment variables in the operating system. If you need to further parse the text of the environment variables, please consult the relevant documentation. The usage of the "set environment variable" command is similar to the "read environment variable" command and will not be explained here.

**Figure 45: Reading environment variables**

In the "system" directory of the "system operations" in the command center, select and insert an "execute command line" command, which can execute Windows scripts. The command has two attributes. In the "command line" attribute, fill in the to be executed Windows script, and in the "output to" attribute, fill in a variable. This variable saves the execution result of the script. For the writing of Windows scripts, please refer to the relevant documents.

**Figure 46: Execute command line**

In the "system" directory of "system operations" in the command center, select and insert a "get system folder path" command. This command can get the path of each system folder. The command has two attributes. For "get directory", Laiye RPA currently supports the acquisition of the following paths: system directory, Windows directory, desktop directory, software installation directory, and start menu directory. In the "output to" attribute, fill in a variable, this variable saves the execution result of "acquisition of system folder path" command, which is the last path obtained.

**Figure 47: Get the system folder path**

The commands "Get temporary folder path" and "Get user folder path" are similar to the "Get system folder path" commands, and will not be explained here.

Application Commands

In addition to simulating human operation of the application through the interface, Laiye RPA can also directly manage the life cycle of the application, start the application, close the application, and obtain the status of the application. In the "application" directory of the "system operation" in the command center, select and insert a "start application" command. This command can start an application. This command has several attributes. In the "file path" attribute, fill in the application to start the file path. The "waiting mode" attribute refers to the waiting relationship between the system and the application. Laiye RPA provides three waiting modes: "do not wait", "wait for application ready", "wait for application execution to exit". "Do not wait" means that the target program starts immediately and the command is completed. "Waiting for the application is ready" means that the application is only started when the application is ready, otherwise the system will always wait. "Wait for application execution to exit" means that after the application is started, the system will wait until the application exits, the command will be executed; the "display style" attribute refers to the way in which the application is displayed when it starts, supported by Laiye RPA. The display styles are: "default", "maximize", "minimize", "hide". "Default" means that the application is started in the default display mode. "Maximize" means that the application window is maximized at startup. "Minimize" means that the application window is minimized at startup, and "Hide" means the application window is not displayed at startup. Finally comes the "output to" attribute, fill in a variable that saves the PID of the application after startup, and this PID will be used in subsequent commands.

**Figure 48: Start the application**

The "start application" command opens an application, but some scenarios require not only the application to open, but also the application to open a file or URL. At this time, the "open file or URL" command can be used. Several attributes of this command are almost the same as the "start application" command. The only difference is the "file path" attribute, fill in the file or URL to be opened here.

**Figure 49: Open file or URL**

After starting the application through the "start application" command or the "open file or URL" command, we can always check whether a specific application is still running while the process is running. Select and insert a "Get application running status" command, which can determine whether a process is active based on the process name or PID. There are two attributes of this command. The "process name or PID" attribute requires the process name or PID of the application. If you fill in the PID, it is the PID obtained from the "output to" attribute of the last "start application" command. If you fill in the process name, you should also fill in the full file name of the application. For example, the process name of the last "start application" command is "notepad.exe"; the "output to" attribute saves the execution result of the command, which is a Boolean value. True indicates the process is still alive; false means the process has been shut down.

**Figure 50: Get the application running status**

Finally, do not forget to close the application. Select and insert a "close application" command, which can close a process based on the process name or PID. There is only one attribute of this command: "process name or PID" attribute, fill in the process name or PID of the application to be closed. The meaning is the same as the attribute of the same name of the "Get application running status" command.

**Figure 51: Close the application**

Dialog

During the operation of the RPA process, generally no human intervention is required. However, in some scenarios, the process requires two-way information communication between people. On the one hand, the key information of the process is notified to people; on the other hand, the control and decision information of people is obtained. The powerful Laiye RPA provides a dialog box mechanism, which can print out key process information or show a dialog box to allow users to make selections and input, realizing the two-way information communication between process and people.

In the "dialog" directory of "system operations" in the command center, select and insert a "message box" command, which will pop up a message box in the middle of the screen during the process.

**Figure 52: Message box**

This command has several attributes. The "message content" attribute fills in the message content body, the "dialog title" attribute refers to the title bar of the pop-up dialog, and the "button style" attribute refers to which buttons are displayed in this dialog. The options for the "button style" attribute are: "Only show OK", "Show Yes and No buttons", "Show abandon, retry and skip buttons", "Show Yes, No and cancel buttons", "Show retry and cancel button", "Display confirmation and cancel button". You can choose the "button style" attribute reasonably according to particular business needs.

**Figure 53: Message box settings**

The "icon style" attribute specifies what icons are displayed in the dialog box. The options are: "Don't display icon", "Display message icon", "Display query icon", "Display warning icon", "Display error icon". Reasonably select the icon for the business scenario; the "timeout" attribute refers to how many milliseconds later the dialog box is forced to close. For example, fill in 5000, which means that after 5000 milliseconds. Even if the user does not click any button of the dialog box, the dialog box will be forced to close. If the "timeout" attribute is filled with 0, it means that the timeout period is not used; that is, the user must click the dialog box, or the dialog box will disappear; the "output to" attribute fills in a variable, which will be changed after the user clicks the dialog button and it will record which button the user clicked. The following flow operation logic can choose different flow directions according to which button the user clicks. The values of the buttons are as follows:

Button valueButton meaning
1OK
2Cancel
3Give up
4Retry
5Skip
6Yes
7No

The "message box" command is a very powerful command. The user can fill in the content, title, button style, or icon style of the message box according to their needs. However, sometimes such a complicated dialog box is not needed, and a simple message notification can pop up. In this case, you can use the "message notification" command. The "message notification" command is also located in the "dialog" directory of the "system operation" in the command center. This command will pop up an operating system notification message in a bubble.

The "message notification" command has several attributes. "Message content", "dialog title", and "dialog icon" have the same meaning as the "message box" command. It should be noted that the "message box" command generally stays for a few seconds before disappearing, but if the process ends, the message box that pops up in the process will also disappear. You can follow the "message box" command with a "delay" command. A delay of a few seconds allows users more time to view the message box.

**Figure 54: Message box settings**

The "message box" command and the "message notification" command realize the process of delivering messages to the user. Although the "message box" command can get "which button the user clicks" to complete part of the user's function of delivering messages to the process, it is very limited. What if the user wants to deliver more information to the process? Laiye RPA provides the "input dialog" command, which pops up a dialog where the user can enter information that needs to be passed, which will be passed into the process.

Let's take a look at the specific usage of the "input dialog" command. The meaning of the "message content" attribute and the "dialog title" attribute is the same as the "message box" command; the "default content" attribute is a prompt message to the user. If the user does not modify it, the content in the "default content" attribute will be passed to the process. The "number only" attribute is a Boolean value: "yes" indicates that the user can only enter numbers and "no" indicates that the user input is not limited, so the user can enter any character. The "output to" attribute requires a variable. When executed, the user's input information will be saved in this variable, and subsequent processes can use this variable, which opens up the channel for the user to enter the process.

**Figure 55: Input dialog**

In addition to supporting user input text, Laiye RPA also supports user input files. Insert an "open file dialog" command, which can pop up an "open file dialog" during the process of running. The user selects the file, and passes the file path to the process. This command has several attributes. The "initial directory" attribute refers to which directory is opened by default when a dialog box is popped up. We can click the folder button to the right of the "initial directory" attribute to select the initial directory. If the initial directory is not selected (i.e. the the default value of the attribute is "") or the selected initial directory does not exist, Laiye RPA will open a default directory as the initial directory. The "file type filter" attribute is a string that indicates which types of files can be opened in this dialog box. For the writing of the file filter, please refer to the relevant documents. The meaning of the "dialog title" attribute is the same as other dialog box commands. Fill in a variable in the "output to" attribute. When the command is executed, the full path of the file selected by the user will be saved in this variable, that is to say, the "open file dialog" does not "open" the file, and it is to get the file path. This variable can be used in the subsequent process, so as to open up the channel for user input to the process.

**Figure 56: Open file dialog**

The "open file dialog [multiple selections]" and "save file dialog" commands are similar to the "open file dialog" command. The "open file dialog [multiple selections]" command can select multiple files. This command returns to an array of file paths, and users can traverse the array to process each file in turn. We will not explain them here.

Clipboard

The operation of the clipboard is a very practical function, which is used to move text and images from one system to another. In addition to using variable storage, using the clipboard is also a common usage. In the "clipboard" directory of "system operations" in the command center, select and insert a "set clipboard text" command, which sets a section of text to the clipboard. This command has only one "clipboard content" attribute. And this attribute fills in the text content to be set in the clipboard.

**Figure 57: Setting clipboard text**

We can then insert a "read clipboard text" command to see if the last "set clipboard text" command was successful. The "read clipboard text" command also has only one attribute---the "output to" attribute. After running this command, the variable sRet filled in the attribute will save the text in the clipboard. Add an "export debugging information" command and output sRet to see if the settings and reading clipboard text are executed successfully.

In addition to transferring text via the clipboard, the clipboard can also transfer images. In the "clipboard" directory of "system operations" in the command center, select and insert a "picture set to clipboard" command, which sets an image file to the clipboard. This command has only one "file path" attribute. This attribute fills in the path of the image file to be set to the clipboard.

**Figure 58: Picture settings to clipboard**

We can insert a "save clipboard image" command to see if the last "picture set to clipboard" command was successful. "Save clipboard image" command has only one "save path" attribute. This attribute fills in the save path of the image file in the clipboard.

**Figure 59: Saving the clipboard image**

Text Writing Screen

The text writing screen is a very intuitive and practical tool command. When running, the log and other information cannot be seen. By writing the text on the screen, whether it is an RPA operation with a maintenance engineer, an end customer, or a record screen software, it can be seen directly. In the "system operation" in the command center, under the "text writing screen" directory, select and insert a "create screen writing object" command, which will create a screen writing object.

**Figure 60: Create screen writing object**

This command has three attributes. "Write screen area" is a JSON string that indicates which area of the screen the text is written on. It is okay if users do not entirely understand this string. Click the range selection button on the right side of the writing screen area. At this time, the interface is covered with a layer of curtain. Laiye RPA will automatically help you choose the screen writing area. For example, the area we just selected is based on the 768×1366 resolution. The starting point coordinates (upper left corner) are (312, 174), the height of the screen writing area is 346, and the width is 598. The units are pixels. The "adaptive" attribute is a Boolean value that indicates whether the writing screen area automatically adapts to changes in resolution. True means that the "writing screen area" attribute will automatically adapt to changes in resolution. False means the "write the value of the screen area" attribute is strictly used to write the screen. The "output to" attribute fills in the write screen object objWindow, and subsequent operations will use this screen write object.

{
"height": 346,
"resolution": {
"height": 768,
"width": 1366
},
"width": 598,
"x": 312,
"y": 174
}

**Figure 61: Setting the screen writing area**

After creating the screen writing object, you can use this screen writing object to draw text. Select and insert a "draw text" command, which will write a piece of text on the screen. This command has four attributes. The "write screen window object" attribute fills in the write screen object objWindow, the "display content" attribute fills in the text content to be displayed, the "text size" fills in the font size of the text, and "text color" fills in the RGB of the text color, where [255,0,0] represents red, [0,0,255] represents blue, and [255,255,0] represents yellow. For the relevant knowledge of RGB colors, please refer to the relevant tutorial.

**Figure 62: Draw text**

If we need to write the screen multiple times, the write screen object objWindow can be used repeatedly. After the last "draw text" command, add a "draw text" command. The two "draw text" commands differ only in the "display content" attribute. After running, I found that the text displayed in the last "draw text" command did not disappear. It turns out that Laiye RPA does not erase the screen writing content of the last "draw text" command by default. If you want to erase the screen writing text, you need to use the "clear text" command. The "clear text" command has only one "write screen window object" attribute. This attribute has the same meaning as the "write screen window object" attribute of the "draw text" command. Just fill in objWindow.

Run the process again, this time the content of the previous text is erased, but the time of the text display is too short. The original Laiye RPA commands are all executed in real time. If text needs to stay on the screen for a period of time, here is a small trick: insert a "delay" command between the "draw text" command and the "clear text" command.

Finally, remember that after all screen writing operations are completed, you must add a "close window" command. This command corresponds directly with the "create screen writing object" to release the objWindow object created by the "create screen object" command.