Build a bot to extract HTML data and perform currency conversion
Als PDF herunterladen
- Zuletzt aktualisiert2020/05/07
Build a bot to extract HTML data and perform currency conversion
Build a bot to extract data from an HTML table to perform a historical currency conversion in order to update fields in the HTML table.
Prerequisites
- To capture UI objects from a web page, ensure that you have installed the product-specific Automation Anywhere Enterprise extension to automate web applications in Google Chrome.
- Ensure that you are familiar with how to build your first bot using the Web Recorder to follow the process in this procedure.
Procedure
- Log in to the Enterprise Client.
- Click New.
- In the Automate window, click Workbench.
-
Open the Variable Manager, click
Add, select Create New
Variable, and add the following eight variables:
- vInvoiceDate: Stores the date for each row extracted from the HTML table. Click Save for each new variable. Click Yes to assign the NULL value to a variable.
- vInvoiceAmount: Stores the invoice amount for each row extracted from the HTML table.
- vRowCount: Sum of the total number of rows in the HTML table (used for looping).
- vTableRow: Custom counter variable used for our HTML data extraction/inserts.
- vInputCurrency: Passed to the Bot Store subtask for conversion. Initial value: GBP.
- vOutputCurrency: Passed to the Bot Store subtask for conversion. Initial value: USD.
- vOutputAmount: Stores the converted input amount from the subtask.
- vResult: Result from the subtask (Shows success after the subtask executes successfully).
-
From the Commands tab, select and drag the
Open Program/File
command to the Actions List.
In the
Open Program/File
window, perform these
steps:
- Step 1: Program/File Path: Browse and select the Google Chrome executable file. Find the file location on your machine, which can be: C:\Program Files (x86)\Google\Chrome\Application. In the Application folder, select chrome.exe.
- Step 2: Start in Path: You can skip this step.
- Step 3: Parameters: Enter the URL for the Automation Anywhere Currency Conversion page: https://www.automationanywhere.com/automationanywherelabs/currency.html
- Click Save.
-
Click Save to save your bot as
Tutorial4_Currency.atmx.
By default, the bot is saved in the My Tasks directory.
- Click Run to test it.
-
From the Commands tab, select and drag the
Object Cloning
command to the Actions List.
- In the Object Cloning window, select Automation Anywhere Labs - CurrencyConversion - Google Chrome. Verify that the target browser session is open in its own window.
- With the Object Cloning window open, click and hold the Capture button. While still holding the left mouse button, highlight the Invoice Table on the Currency Conversion page until a red border blinks around it. Now release the button.
- In the Select Action to Perform drop-down list, select Get Total Rows.
- In the Assign to Variable drop-down list, select vRowCount.
- Click Save.
-
From the Commands tab, expand (+) the Loop command and drag Times to the
Actions List.
- In the Times field of the Loop window, press F2 and select the vRowCount variable.
- Click Save.
-
From the Commands tab, expand (+) the
IF/ELSE
command to open a series of IF/ELSE commands.
- Click and drag the IF/ELSE Variable command to the bottom of the Actions List.
- Click Edit next to the If Condition field.
- Set the Variable field: press F2 and select Counter from System Variables.
- Set the Operator drop-down value to Greater Than (>).
- Select the Fix option, and set it to 1.
- Click Save.
-
From the Commands tab, select and drag the Object Cloning command inside the IF statement..
- In the Object Cloning window, select Automation Anywhere Labs - CurrencyConversion - Google Chrome.
- With the Object Cloning window open, click and hold the Capture button. While still holding the left mouse button, highlight the Invoice Table on the Currency Conversion page until a red border blinks around it. Now release the button.
- In the Select Action to Perform drop-down list, select Get Cell Text by Index.
- Set the Row field: press F2 and set it to Counter.
- Set the Column field to 5 (as the Invoice Date is the 5th column).
- In the Assign to Variable drop-down list, select vInvoiceDate.
- Click Save.
-
Repeat Step 11 and add a second Object Cloning command
to capture the Invoice Amount:
- Repeat Steps 11a and 11b, and then in Step 11c, set the Column value to 6
- In Step 11d, for Assign to Variable, select vInvoiceAmount.
-
From the Commands tab, select and drag the Variable Operation command under the Object Cloning command that was added to extract the
vInvoiceAmount.
- In the Specify Variable drop-down list, select vInvoiceDate.
-
In the Specify value for $vInvoiceDate$ field,
insert
"$vInvoiceDate$"
(include the quotation marks). - Click Save.
- In a new browser window, navigate to http://botstore.automationanywhere.com. Search, download, and install the Look Back Currency Conversion Bot (Look Back Currency Conversion).
-
From the Commands tab, expand (+) the
Task command to open up a series of
Task commands.
- Click and drag the Run Task command to the Actions List under the Variable Operation command.
-
Click Browse to select
LookBackCurrencyBot_Subtask.atmx.
Find the file location on your machine, which can be: C:\Users\<Your User Account>\Documents\Automation Anywhere Files\Automation Anywhere\My Tasks\Bot Store\Look Back Currency Conversion-Automation Anywhere\My Tasks
-
Click the Variable option to map values from the
Main Task Variable to the Run Task
Variable. Use Quick Map or use
+ Add and add any missing variables.
Main Task Variable Run Task Variable vInputCurrency
vInputCurrency
vOutputAmount
vOutputAmount
vOutputCurrency
vOutputCurrency
vResult
vResult
vInvoiceDate
vCurrencyDate
vInvoiceAmount
vInputAmount
- Click Save.
-
From the Commands tab, select and drag the
Variable Operation command to the Actions List.
- In the Specify Variable drop-down list, select vTableRow.
-
Set the Specify value for $vInvoiceDate$ field
to: $Counter$-1.
vTableRow must have one value lower than Counter so that it will work with a dynamic DOMX path on the HTML table, which uses 0 based row counting.
- Click Save.
-
From the Commands tab, select and drag the Object Cloning command to the Actions List below the Run Task command.
- In the Object Cloning window, select Automation Anywhere Labs - CurrencyConversion - Google Chrome. Verify that the target browser session is open in its own window.
- With the Object Cloning window open, click and hold the Capture button. While still holding the left mouse, highlight the Payment Amount$ (first input field) on the Currency Conversion page until a red border blinks around it. Now release the button.
- In the Select Action to Perform drop-down list, select Get Cell Text By Index.
- In the Select Search Criteria section, select the binoculars icon for all fields except DOMXPath, HTML Tag, and HTML Type.
- Double-click the Value field for the DOMXPath value. Delete the existing value and enter: /html/body/main[1]/div[1]/table[1]/tbody[1]/tr[$vTableRow$]/td[6]/input[1]
- Set the Select Action to Perform drop-down value to Set Text.
- In the Text to Set field, press F2, select vOutputAmount, and click Insert.
- Click Save.
-
With the
Object Cloning
window open, click and
hold the Capture button. While still holding the left
mouse button, highlight the Submit button on the Currency
Conversion page until a red border blinks around it. Now release the
button.
- In the Select Action to Perform drop-down list, select Left Click.
- Click Save.
- Save your bot and click Run.