select chapter

laiye rpa developer guide d1-博天堂登陆

as mentioned earlier, the laiye rpa process block can be written in visual view or a code view. both have advantages and disadvantages. in the previous chapters, we used the visual view as an example. in this chapter, we will talk about how to use the source code to implement the functions that have been implemented previously.

although laiye rpa can be used entirely from visual view, once you master code view, the efficiency of creating robots will be greatly improved. we recommend readers with basic programming knowledge to learn it if possible.

a process block is opened with laiye rpa creator, and the visual view appears by default. there is a switch on the left and right side of the visual view. turn it to the "source code" side to open the code view.

after opening the code view, your first thoughts are probably that: 1) the neatly arranged boxes are no longer used to display commands; 2) the property/variable bar on the right disappears. of course, we mentioned in the code view section that laiye rpa’s visual view and code view are merely two ways of presenting the same information and the user can change between them at anytime. so, how do these commands, attributes and variables behave in the code view?

the code-view of laiye rpa follows the following rules:

  • use a source code file to represent a process block, and the default extension of the source code file is .task

  • use function calls to represent a command

  • use the parameters passed in when a function is called to represent the attributes of the command

  • use dim statements to define variables

it is not difficult to see from the figure that the command of "start ie browser" is actually a call to the function webbrowser.create in the code view; each property set when starting ie browser is a variable in the function call, such as "about:blank", etc.; the variables used in the command need to be defined in dim language.


figure 3:visualization view and corresponding code view

an example is shown above. in the visual view, we can simply drag and drop, insert a "start ie browser" command, and set its properties. in contrast, the code view display is indicated by the orange arrow.

laiye rpa supports a very rich set of commands that are represented as functions in the source view. therefore, laiye rpa actually built a large function library on the basis of laiye botscript. among them, some of the most commonly used functions do not have a namespace, such as the delay function; other functions contain a namespace, such as the webbrowser. in the previous example, the "create" function’s namespace is webbrowser. for namespace-free functions, most of them are implemented in one module through the multi-module mechanism in laiye botscript. therefore, relevant modules need to be imported by the import language before use, such as the webbrowser.create function. of course, there are several basic functions whose namespaces are automatically imported, so we do not need to import them again, including math, log, and json.

in this article, we only list the main namespaces and their functions supported in the current version for readers' reference. note that, as mentioned in [previous][language reference], the names and keywords in the laiye botscript are case-insensitive, so each namespace listed in the following table can be written in all uppercase, all lowercase, or mixed case schemes.

namespace

function overview

mouse

mouse simulation related functions

keyboard

keyboard simulation related functions

uielement

various operations on interface elements

text

various operations on text on interface elements

image

in [no target command] [no target command], various operations are performed through images

ocr

in [no target command] [no target command], get the text by identifying the image content

webbrowser

various browser operations

window

various operations on windows in the windows operating system

excel

various operations on excel

word

operations on word

file

common file reading and writing and other related functions

ini

ini format file reading and writing and other related functions

json

conversion of the json format string to and from the dictionary type in laiye rpa

sys

operations related to operating system

http

access related functions of http service

log

related functions for recording logs during process operation

regex

regular expression matching and search related functions

math

math related functions

time

time related functions

app

various operations on the application

csv

csv format file reading and writing and other related functions

mail

operations on email

clipboard

various operations on the clipboard

dialog

pops up various dialogs, which can be used for simple interaction with end users

set

collection related function


for example, we are interested in the functions of mouse. one way is to consult the documentation to see what functions are under this namespace and what parameters each function has. in addition, there is another faster method, which is described below:

  1. in the code view of laiye rpa creator, find a blank line and type mouse

  2. type ‘.’ for all the functions in the mouse namespace to be listed automatically

  3. continue to press the up and down arrows to select, and each selected function will display a brief description of its function, and then press enter to confirm the function to be used

  4. type a left parenthesis (at this time, the parameters of this function will be automatically listed, and the description of the first parameter is displayed

  5. after that, each time you enter a parameter, after the parameter is separated by a comma, it will automatically switch to the description of the subsequent parameter

the above process is roughly as shown in the figure below:


figure 4:quick view of function list and description


we have learned how to use the visual view in the previous tutorial: insert a click target under the "mouse" category, and select the windows start menu button as the target.

after inserting the command in the visual view, switch to the source view to see how the command appears in the source view (in order to make it easier to see, the statement is wrapped here, but it does not affect the code):


figure 5: source code view of "click on target" operation

it looks so complicated! but do not be afraid; let's simplify:

the first line, starting with the # symbol, can simply be regarded as a special comment, which has no effect on the operation of the process and can be omitted. in fact, it is displayed in light gray in laiye rpa creator.

the end of the first line is actually a function call to the function mouse.action, which takes five arguments. in practice, however, only the first argument is required, and subsequent arguments can be omitted. we may wish to remove all the content that can be omitted and just leave out the following:


figure 6: source code view of "click on target" operation (simplified)

it is not difficult to see that the function has only one parameter left. this parameter is a dictionary type and represents the target to be clicked. of course, even with this simplification, the contents of this dictionary type are difficult to write by hand. what to do? please note that at the top of the source view, there are four buttons "element", "image", "window" and "area", and corresponding hotkeys alt 1, alt 2, alt 3, alt 4 (as shown below). since we need to use an interface element as the target of the command, here, click the "element" button.


figure 7: shortcut button above the code view

after clicking, laiye rpa creator interface disappears temporarily, and a "target selector" appears, which is a translucent mask with red border and blue background. the usage of this "target selector" is exactly the same as the method of selecting a target in the visual view, just move the mouse to the target, and when the mask is just covering the target, click the left mouse button. if you are not familiar with the operation of the "target selector", please review the relevant content of the previous tutorial.


figure 8: interface of the target editor

after selecting the target, the "target editor" dialog box of laiye rpa creator will pop up, as shown in the figure below. we have previously learned how to use the target editor to modify the characteristics of the target to avoid "misselection" or "missing selection" of the target. the usage here is still the same as before, with only a slight difference: the button in the lower right corner becomes "copy to clipboard". this reassembles the target's various features into a dictionary type value, and copies this value to the operating system's clipboard in the form of text. after that, you only need to go back to the code view and paste this text from the clipboard into the mouse. action as a parameter to complete the writing of this command.

paste this text into notepad and you will see that it is the value of the dictionary type describing the target:


next, let's see how we can save the image of the start menu button in an image file. this can be done by using the uielement.screenshot function. this function has two mandatory parameters. the first parameter is still to specify the interface element as the target, and the second parameter is the path of the image file to be saved. in other words, the first parameter is exactly the same as the previous mouse.action parameter. just paste what you just copied to the clipboard right here; the second parameter can write a file path, such as "c:\ \temp\\1.png". there are two noteworthy details here:

  • because you need to write files, please note that you need to write to a path with permissions. for example, laiye rpa is not started with an administrator account by default, so paths such as "c:\\" do not have permissions to write, but "c:\\temp" does.

  • we used a string to represent the file path. according to the laiye rpa rule in the previous chapter, an escape character \\ is used to represent a backslash \ in the string, so the path needs to be written as "c:\\temp\\1 .png" format.

save and run, and you can see the image of the start menu button is saved as a file.

looking back at this source code, it is not difficult to find that the "start menu button" target has been reused twice, which is not appropriate. let's reshape it a little bit and make it look like this:

this looks much clearer.

网站地图