Write an RPA example using TagUI and Robocorp

Posted by juneym on Sat, 11 Sep 2021 05:05:56 +0200

RPA example

RPA software

There are many open source RPA software, which will be used next TagUI,Robocorp and WeAutomate Studio As an example, WeAutomate Studio is Huawei's RPA tool, and the developer designer has a 3-month trial period.

TagUI

TagUI is maintained by AI Singapore. It is an RPA command line interface tool that can run on any major operating system. First, download the TagUI from github and select the corresponding Operating system version

1. Installation

TagUI installation is very simple

1. Download the corresponding operating system version

2. Unzip it to your software directory

3. Install JDK (ensure that there is a JDK environment locally, which is recommended on the official website) Amazon Corretto 8)

4. Add the corresponding system directory \ tagui\src to the system environment path

5. Install chrome browser (tested but not used)

6. Open CMD and enter tagui to see if the installation is successful

2. Operation

Running the written automation process is also very simple. Use tagui demo.tag in the corresponding automation file. Tag directory

Several ways to start tag:

1. You can use the complete path: tagui d:\tagui\samples\demo.tag

2. Create a. cmd file. Double click to use: tagui demo.tag -d

3. Hide the browser to run: tagui demo.tag -h

4. Create a. cmd file and hide the browser: tagui demo.tag -h -d

3. Write. tag automation file

The following is an official example demo:

// This flow makes a search on Google, clicks the first result and screenshots the page

// First, visit google.com
https://www.google.com

// Look on the web page for an element with 'q' in its text, id or name
// (or some other attributes), then type 'latest movies' and enter
// type q as latest movies[enter]

// Use a more accurate identifier below instead because
// google.com webpage differs for different locations
type //*[@name="q"] as latest movies[enter]

// Click the first result using XPath
// Learn XPath: https://www.w3schools.com/xml/xpath_intro.asp
click (//*[@class="g"])[1]//a

// Wait 3 seconds so the page can load
wait 3

// Save a screenshot of the web page to top_result.png
snap page to top_result.png

You can see some keywords: click, type, wait, snap

Click is to click an element on the web browser: the syntax is click [DOM / xpath / point / image], followed by xpath path, name or id. xpath is recommended. xpath can be obtained directly from the element selector of chrome browser.

Type is to assign a value to an element. For example, you can assign a value to the search box of google search: type //*[@name="q"] as TAGUI[enter], where / / * [@ name = "q"] is the xpath of the search box, TAGUI is the content to be entered, and [enter] is the carriage return after input. The syntax is: type [DOM/XPath/Point/Image] as [text to type]

wait 3 means waiting for 3 seconds.

Snap is a screenshot that can save an entire page, element, or region. The syntax is snap [DOM/XPath/Region/Image/page] to [filename].

4.demo example

Here's a simple example: for example, I want to open Baidu web page to search for recent movies and click the first search result, then intercept the current page and save it. At this time, the. tag file can be written like this

//Open Baidu home page
https://www.baidu.com/

//Search for recent movies and enter
type //*[@ id="kw"] as recent movie [enter]

//Click the desired result
click //*[@id="2"]/h3/a

//Pop up a new page
popup new
    wait 2
    //Intercept the corresponding div and save it to the corresponding path
    snap //*[@id="content"]/div/div[2] to movies.png

Then we can execute it directly by using the command tagui movie.tag.

Screenshot of the final execution result:

5. Some other orders

In addition to the click and type just used, there are many commands you can refer to Official documents

Robocorp

In fact, robocorp is similar to tagui, but only in the gap of commands. Robocorp has rich extensions. You can write robocorp code with the help of vscode. Just download the robocorp extension in vscode.

1. Install Robocorp Lab

Robocorp lab is the official development tool, download address Developer-first RPA: Python-based technology | Robocorp , download and install directly.

2. Use Robocorp lab

We can create a new robot or import an existing project.

Take a name, and then the template selection criteria can be created and written.

3. Write demo

Similarly, we directly reference the documentation to write a demo, so that we can more intuitively see how the program runs. We get the latest movie screenshots like TagUI.

1. The first is the Settings module. We need to operate the elements on the browser, so we use the RPA.Browser.Selenium dependency

*** Settings ***
Documentation     MY first RPA
Library           RPA.Browser.Selenium

2. Next, let's write the Task we need to perform, which is the Task module

*** Tasks ***
#Name of the task
Get information on the latest movies
    #Task steps
    Open a browser

3. We wrote a task step called Open a browser, but the robot can't recognize how Open a browser is defined and what it is used for, so we need the Keywords module at this time

*** Keywords ***
#Define what Open a browser needs to do
Open a browser
	#Open a web page using a browser
    Open Available Browser    https://www.baidu.com/
    #Open Available Browser is an abbreviated method in RPA.Browser.Selenium dependency. It's good to directly reference it

4. A complete robot includes these three modules: Settings, Task and Keywords. OK, after knowing the operation logic, we can refer to the document to write a complete code example:

*** Settings ***
Documentation   latest movies.
Library         RPA.Browser.Selenium

*** Keywords ***
Open a browser
    Open Available Browser    https://www.baidu.com/
    
*** Keywords ***
Search for recent movies
    Input Text      //*[@ id="kw"] recent movies
    Submit Form
    
*** Keywords ***
Get screenshots
    Click Element When Visible    css:div.result:nth-child(2) > h3:nth-child(1) > a:nth-child(1)
    ${handles}=    Get Window Handles
    Switch Window    ${handles}[1]
    Wait Until Page Contains Element    css:.panel
    Screenshot   css:.panel    ${CURDIR}${/}output${/}screenshot.png


*** Tasks ***
#Name of the task
Get information on the latest movies
    #Task steps
    Open a browser
    Search for recent movies
    Get screenshots

After writing, click Run all to see the running process of the robot

(results after operation)

5. Other methods

The demo also contains many defined methods, direct reference, complete dependencies and all methods: Robocorp documentation

Topics: Python AI crawler rpa