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.

    Install plug-ins

  • Ensure that you are familiar with how to build your first bot using the Web Recorder to follow the process in this procedure.

    Build your first bot using Web Recorder

Procedure

  1. Log in to the Enterprise Client.
  2. Click New.
  3. In the Automate window, click Workbench.
  4. Open the Variable Manager, click Add, select Create New Variable, and add the following eight variables:
    1. 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.
    2. vInvoiceAmount: Stores the invoice amount for each row extracted from the HTML table.
    3. vRowCount: Sum of the total number of rows in the HTML table (used for looping).
    4. vTableRow: Custom counter variable used for our HTML data extraction/inserts.
    5. vInputCurrency: Passed to the Bot Store subtask for conversion. Initial value: GBP.
    6. vOutputCurrency: Passed to the Bot Store subtask for conversion. Initial value: USD.
    7. vOutputAmount: Stores the converted input amount from the subtask.
    8. vResult: Result from the subtask (Shows success after the subtask executes successfully).
  5. 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:
    1. 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.
    2. Step 2: Start in Path: You can skip this step.
    3. Step 3: Parameters: Enter the URL for the Automation Anywhere Currency Conversion page: https://www.automationanywhere.com/automationanywherelabs/currency.html
    4. Click Save.
  6. Click Save to save your bot as Tutorial4_Currency.atmx.
    By default, the bot is saved in the My Tasks directory.
  7. Click Run to test it.
  8. From the Commands tab, select and drag the Object Cloning command to the Actions List.
    1. In the Object Cloning window, select Automation Anywhere Labs - CurrencyConversion - Google Chrome. Verify that the target browser session is open in its own window.
    2. 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.
    3. In the Select Action to Perform drop-down list, select Get Total Rows.
    4. In the Assign to Variable drop-down list, select vRowCount.
    5. Click Save.
  9. From the Commands tab, expand (+) the Loop command and drag Times to the Actions List.
    1. In the Times field of the Loop window, press F2 and select the vRowCount variable.
    2. Click Save.
  10. From the Commands tab, expand (+) the IF/ELSE command to open a series of IF/ELSE commands.
    1. Click and drag the IF/ELSE Variable command to the bottom of the Actions List.
    2. Click Edit next to the If Condition field.
    3. Set the Variable field: press F2 and select Counter from System Variables.
    4. Set the Operator drop-down value to Greater Than (>).
    5. Select the Fix option, and set it to 1.
    6. Click Save.
  11. From the Commands tab, select and drag the Object Cloning command inside the IF statement..
    1. In the Object Cloning window, select Automation Anywhere Labs - CurrencyConversion - Google Chrome.
    2. 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.
    3. In the Select Action to Perform drop-down list, select Get Cell Text by Index.
    4. Set the Row field: press F2 and set it to Counter.
    5. Set the Column field to 5 (as the Invoice Date is the 5th column).
    6. In the Assign to Variable drop-down list, select vInvoiceDate.
    7. Click Save.
  12. Repeat Step 11 and add a second Object Cloning command to capture the Invoice Amount:
    1. Repeat Steps 11a and 11b, and then in Step 11c, set the Column value to 6
    2. In Step 11d, for Assign to Variable, select vInvoiceAmount.
  13. From the Commands tab, select and drag the Variable Operation command under the Object Cloning command that was added to extract the vInvoiceAmount.
    1. In the Specify Variable drop-down list, select vInvoiceDate.
    2. In the Specify value for $vInvoiceDate$ field, insert "$vInvoiceDate$" (include the quotation marks).
    3. Click Save.
  14. 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).
  15. From the Commands tab, expand (+) the Task command to open up a series of Task commands.
    1. Click and drag the Run Task command to the Actions List under the Variable Operation command.
    2. 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
    3. 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
    4. Click Save.
  16. From the Commands tab, select and drag the Variable Operation command to the Actions List.
    1. In the Specify Variable drop-down list, select vTableRow.
    2. 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.
    3. Click Save.
  17. From the Commands tab, select and drag the Object Cloning command to the Actions List below the Run Task command.
    1. In the Object Cloning window, select Automation Anywhere Labs - CurrencyConversion - Google Chrome. Verify that the target browser session is open in its own window.
    2. 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.
    3. In the Select Action to Perform drop-down list, select Get Cell Text By Index.
    4. In the Select Search Criteria section, select the binoculars icon for all fields except DOMXPath, HTML Tag, and HTML Type.
    5. 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]
    6. Set the Select Action to Perform drop-down value to Set Text.
    7. In the Text to Set field, press F2, select vOutputAmount, and click Insert.
    8. Click Save.
  18. 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.
    1. In the Select Action to Perform drop-down list, select Left Click.
    2. Click Save.
  19. Save your bot and click Run.