BACK

v11 Tutorial: Perform Language Translation

Prerequisites

You’ll need to have Automation Anywhere Enterprise v11 workbench installed and licensed with a bot creator license to follow along with this lab.

Background

A natural part of building bots is making best use of all the commands, tools (and even other bots as we’ll see) that are available to you. In this exercise, a message is provided to us in a foreign language. Our job is to create a bot that can read that message from the page, translate that message, and return the translated text back to the website for verification. To accomplish this task, we’ll integrate a Bot Store utility-bot (to help with the translation) with our own bot’s logic.

Exercise Page: https://www.automationanywhere.com/automationanywherelabs/translate.html

Pseudocode

Let’s start with our pseudocode again. Remember, think of pseudocode as the human readable steps that our bot will need to accomplish. Once we have that pseudocode shell – its much easier for us to go back and start filling in the pieces to complete each task. To get started thinking about the steps we’d need to take – look at the exercise page to understand the specifics of this exercise.

Step 1: Launch Website – We’ll have to have the website open before we can start extracting content or entering data.
Step 2: Read Text to Decode From Page – Our bot will have to read the message from the page so we would know what to translate.
Step 3: Pass Text to the Bing Translate Bot – Since we’ll be leveraging a Bot Store bot here, we just need to worry about getting the bot the proper text, and letting the Bing Translate bot handle the rest.
Step 4: Collect the Results of the Bing Translate Bot – The Bot Store bot should return to us the data we need, so we’ll have to store that data someplace so we can enter it into the web form.
Step 5: Enter Translated Text into Website Field – Once the translated text comes back, we’ll pull it out from where we stored it (variables) and enter it into the input field on the site/
Step 6: Click the Submit Button – The last step for our bot is to press the Submit button for us so the site can validate if our translation of the Text to Decode is correct.

Building the Bot

We have a good start on our requirements and we understand what needs to happen for this exercise to be completed successfully. We’ll be building from scratch on this one, so we’ll need to create brand new bot.

  1. Launch and login to the Automation Anywhere Client (Either Enterprise or Community – either will work).
  2. In the upper left corner of the screen, click the “New” button.
  3. An “Automate” dialogue will appear asking how you want to get started. Press the Workbench button to continue.
  4. A blank Workbench session will open. Before we get started adding commands to our Actions List, we’ll need to create some variables to store some of our data for this exercise. Variables are used to label and store data that our bot uses for processing.
    1. In Automation Anywhere, the best practice is to prefix custom variables with a lower-case v then use camel case naming with no spaces for the rest of the variable name.
  5. To create your first variable, click on the Variable Manager tab on the far-right side of your Workbench window. Clicking this tab will expand the Variable Manager tab.
  6. We’ll need 3 variables for this exercise.
    1. vExtractedText: We’ll need a variable to store the text that we extract from the website.
    2. vOutputLanguage: We’ll need a variable to store the target translation language which we’ll have to provide to the Bing Translate Metabot.
    3. vTranslatedText: We’ll need a variable to store the translated text that we get back from the Bing Translate Metabot we’re going to call.
  7. With the variable manager tab expanded, click the Add button to add a new Variable. An Add Variable dialogue will appear.
  8. In the Add Variable dialogue, enter vExtractedText into the Name field leaving the Variable Type as Value and the Select dropdown as Value.
    1. We’re going to leave the variables we create blank for now, because we’ll let the bot take care of assigning the variables a value.
  9. Press the Save button to save your newly created variable. A pop-up will appear indicating that we are assigning a NULL value to our variable. That just means we have left the variable unassigned – which is what we want, so press Yes to dismiss this dialogue.
  10. We need to repeat those steps again to create our vTranslatedText variable. Press the Add button on the Variable Manager tab to create our next variable.
  11. In the Add Variable pane that appears, enter vTranslatedText as the Name and press the Save button.
  12. Once again, press Yes to dismiss the NULL value to variable! dialogue.
  13. We need to repeat those steps to create one last variable – to create our vOutputLanguage variable. Press the Add button on the Variable Manager tab to create our next variable.
  14. In the Add Variable pane that appears, enter vOutputLanguage as the Name. This time, we will give a value to our variable at time of definition. Enter English into the Value field and press the Save button.
  15. The first real action we need our bot to take is to launch our web browser and navigate to the specific page we’re going to be using for our automation. From the commands tab on the left side of the screen, click and drag the Open Program/File command over on to the Actions List.
  16. As soon as you drag this Open Program/File command over, notice that it pops-up with a dialogue asking for a couple parameters.
    1. The Step 1 field is the Program/File Path. Press the browse button next to this field to open a windows explorer window. Here, you’ll give the specific instruction to open a particular application. In the case of this tutorial, we want to select the Google Chrome executable file. For me, that’s located in C:\Program Files (x86)\Google\Chrome\Application\. Your path is likely very similar if not the same. In that folder, select the chrome.exe executable and press the Open button to close the dialog.
    2. The Step 3 field is the other field we’re concerned with in this command. In step 3, we give a parameter to be used with the application selected in Step 1. For us, that parameter will be the URL of our tutorial page: https://www.automationanywhere.com/automationanywherelabs/translate.html
    3. Press the Save button to close the Open Program File Command.
  17. You should now see your first command showing up in the Actions list in the middle of the screen.
  18. Press the Save button with the disk icon at the top of the screen to save this new bot.
  19. When prompted, give the name Tutorial2_Translate and press the Save button to close to Save Task dialogue.
  20. Once the bot has been saved, press the Play button to launch the bot.
  21. In the bottom right corner of your screen, you should see a dialog window appear which shows the progress of your bot’s execution. In our case, out bot only has 1 line, so that window will pop up quickly and close as the bot has finished its execution.
  22. As the bot runs, you should see that Google Chrome opens and automatically navigates to the page we provided in the Open Program/File command.
  23. Verify that Google Chrome launches and automatically navigates to our exercise page. Leave this window open as we’ll use it for the next commands which we’ll be adding.
  24. In the Commands tab on the left side of the workbench, click and drag the Object Cloning command into the Action List.
  25. The Object Cloning window will appear. From Select Window dropdown, select the window titled Automation Anywhere Labs – Translate – Google Chrome
    1. If you don’t see this window title, make sure that the window which launched as a result of step 19 is still open. If its open, but opened as a tab behind another browser, click and drag the tab off the browser so that our target browser session is open in its own chrome window.
    2. Click and hold the Capture button. Automation Anywhere will automatically switch to the application indicated in the Select Window dropdown – in this case our Google Chrome Translate exercise page. With the left-click on your mouse still held down, highlight over the Text to Decode until there is a red box flashing around the entire Text to Decode body of text. Once the red box has highlighted the target body of text, you can release the left-click.
    3. The Automation Anywhere Workbench should set the focus of your screen back to the Object Cloning properties window. Click the up-arrow icon to explore all the Search Criteria that the Object Cloning command knows about our target object.
    4. The Object Cloning – Search Criteria window will appear. Here we can see all the HTML/document properties that the Object Cloning command was able to identify about the section of the page which we highlighted. It’s good for us to check this because we’re attempting to extract the message that we need to translate from the page, so we need to see which property that text is stored in.
      1. Looking through the list of properties, we can see there is a property called HTML InnerText. We can see that HTML InnerText has the full message that we highlighted…unfortunately with the “Text to Decode:” part included, so we’ll have to clean that up. For now, we need to make note that we want to store the value for HTML InnerText in our vExtractedText variable.
      2. Press the OK button to close the Object Cloning – Search Criteria window so we can set up our variable.
    5. Back on the Object Cloning window, we’ll need to set up which action we need to take on this object.
      1. In the Select Action to Perform dropdown, select Get Property. We select this because in this instance, we want the Object Cloning command to extract data from the page.
      2. In the Select Property dropdown, select HTML InnerText. We specify this property, because this is the property which contains our target text as we saw in the Object Cloning – Search Criteria window.
      3. In the Assign to Variable dropdown, select the variable we created in step 8 – vExtractedText.
      4. To summarize – we are telling the Object Cloning command that we want to extract the HTML InnerText value from the selected object and assign its contents to our vExtractedText variable. Once you have these drop downs set properly, press Save to close the Object Cloning window.
  26. We have our command to extract our text from the page in place, however it’s extracting more text than we need.
    1. Text being extracted: Text to Decode: Превръщаш се в шампион на ботове. Досега си се правила добре на практика.
    2. Text we actually want: Превръщаш се в шампион на ботове. Досега си се правила добре на практика.
    3. Note: Why couldn’t we just extract the part we needed from the beginning? The HTML of the page we’re working on makes no distinction between the word “Text to Decode:” and the Bulgarian text – so the Object Cloning also can’t make a distinction. We have to extract the entire block, then pull out what we may need. This is quite common when extracting content from pages, also known as Web Scraping.
  27. Fortunately, Automation Anywhere has some helpful String Operation commands that can assist us extracting just the text we’re interested in. In the Commands Tab on the left side of your screen, scroll down until you find the String Operations command. There are several of them, so click the ‘+’ next to String Operation you’ll see them all.
  28. Drag the Before-After command into the Actions List so we can clean up the text.
    1. The Before-After String Operation command returns a portion of our text surrounded by any provided Before or After text provided. We can provide before text, after text, or both. In our case, we know there is specific text that comes before the text that we care about.
    2. In the String Operation window that appears, we need to give a source string – which is where the full text that we extracted exists. We stored it in our vExtractedText variable.
      1. Click into the Source String field and press the F2 button on your keyboard to bring up the Insert Variable window. This will allow us to select our variable from a list without having to type anything.
      2. Select the vExtractedText from the Insert Variable window and press the Insert button.
    3. Click into the Before text field. We need to tell the bot what text to expect before the text we care about. In our case, its Text to Decode:
    4. There is nothing that comes after our target text, so we can leave that field blank.
    5. Our final step on the String Operation window is to select the Assign the Output to Variable dropdown. Select vExtractedText from the dropdown so we can assign our target text back to the original variable that it came from.
    6. Press Save to close the String Operation window.
  29. At this point, the Bulgarian text should be all that’s left in our vExtractedText variable. When building bots, it’s helpful to test things along the way so that if something isn’t right, it can be addressed right away as opposed to not knowing where to look if an error occurs at the end of your build. Let’s do that now by adding the Message Box command to our bot by dragging the command from the Commands pane into the Actions List.
    1. When the Message Box command has been added, it will pop up with a Message Box configuration window, which allows you to enter a message to show the user. A Message Box is a message that can be displayed to the user in run-time to let you know how variables are being filled, provide a message, etc. Message boxes should not typically be used in bots that are going into production as there may or may not be a human there to dismiss a message box.
    2. In the Please enter message to show the user field, press the F2 button to bring up the Insert Variables dialogue.
    3. Select vExtractedText and press the Insert button to close the Insert Variables window, and the Save button to close the Message Box window.
    4. Press the Save button at the top of the screen with the blue disk icon, then press the green Play button to run the bot.
  30. Once the bot executes, you should see that it opens Google Chrome, navigates to our target exercise page, then pops up with a message box of our Bulgarian text.

    1. If your message box still included the phrase Text to Decode:, check to make sure you have the Before-After string operation set up correctly.
  31. Since we proved we were able to get just the Bulgarian text from the website with our Message Box test, right click on the Message Box command in the Actions List and select Disable from the context menu that appears. This will keep the Message Box line in our actions list but prevent it from ever executing again until we re-enable it.
  32. We’re now ready to translate our Bulgarian text to English. Scrolling through the list of available commands in the Commands Pane, notice that no command is explicitly available for language translation. It is at this point that our bot will leverage the building capabilities and expertise of vendors, partners, and individuals who build for the worlds largest RPA marketplace – Automation Anywhere’ s Bot Store. With Bot Store, we can expand on the existing command set with pre-built bots and components.
    1. In a new chrome tab, navigate to http://botstore.automationanywhere.com
    2. In the search field at the top of the page, enter Bing Translate Bot and click the icon to search.
    3. The first result should be the correct bot as the title is exactly: Bing Translate Bot (If you’re not sure you have the right one, you could alternatively try this direct link)
    4. Press the Get Bot button on the listing page to initiate the process of downloading the bot.
      1. Note: Bot Store uses the same login as your aPeople account. If you haven’t yet registered for an aPeople/Bot Store account, you’ll need to do so to continue with the bot download. Both the account and the bot are free.
    5. The Bing Translate Bot will download as a .msi file in your default downloads directory.
    6. Double-click the Bing Translate-Automation Anywhere.msi installer in your downloads directory (likely C:\Users\<your username>\Downloads).
    7. When the installer starts, press the Next button to get to the Terms & Conditions screen.
    8. Upon accepting the Terms & Conditions and selecting the appropriate I accept the terms…radio button, the license key field will become enabled.
    9. Enter the license key. It should be emailed to the email address used to register for Bot Store access. Alternatively, the key is available on Bot Store’s downloads page.
    10. Press the Next button to continue, and finally click Install to begin the installation.
    11. Once the installation has completed, press the Finish button to close the installer.
  33. The Bing Translate Bot just installed 2 components:
    1. MasterBot.atmx (atmx is a bot-file format) – which is a sample bot showing how to utilize the Bing Translate Bot’s MetaBot – we wont need it for this exercise, but you can surely check it out later.
    2. BingTranslate.mbot (mbot is a MetaBot-file format) – which is a reusable component we will invoke to handle our translation.
    3. It also installed a ReadMe file which can be referenced in the future for additional details on how to use the bot – located in the My Tasks\Bot Store\Bing Translate–Automation Anywhere folder
  34. Back in the Automation Anywhere Workbench, next to the commands tab on the left side of the screen, click on the MetaBots tab to show the installed MetaBots.

    1. There should now be a metabot showing up named BingTranslate.mbot. Click and drag this MetaBot below the last line in your Actions List.
    2. The MetaBot configuration window will appear. Here we must map our 3 variables to the 2 input and 1 output parameter of the Translate Text logic of the BingTranslator metabot.
      1. Click the Value field next to the vInputText field in the MetaBot configuration window. Press F2 to bring up the Insert Variables explorer and select the variable vExtractedText. Press Insert to insert the variable.
      2. Click the Value field next to the vOuputLanguage field in the MetaBot configuration window. Press F2 to bring up the Insert Variables explorer and select the variable vOutputLanguage. Press Insert to insert the variable.
      3. Click the Value field next to the vOutputText field in the MetaBot configuration window (in the Output Parameters section on the right). Press F2 to bring up the Insert Variables explorer and select the variable vTranslatedText. Press Insert to insert the variable.
      4. Press Save to close the MetaBot configuration window.
  35. We’ve covered 4 of our 6 defined Psuedocode steps. The Bing Translate Bot should feed us back the translated text to our variable – vTranslatedText. That variable needs to now be mapped back to the input field on our exercise page.
  36. Back on the Commands Tab within our Automation Anywhere Workbench window (you’ll likely have to switch back from the MetaBots tab we were previously using), drag and drop an Object Cloning command to the end of the Actions List.
  37. With the exercise page still open in Google Chrome (open it again if not already open) – Select the Automation Anywhere Labs – Translate – Google Chrome selection for the Select Window drop down, then left-click and hold the Capture button to begin an Object Clone.
    1. Hover the cursor over the Enter Translated Message Here to Validate field until its border is flashing with a red outline, then release.
    2. Instead of extracting text for this Object Clone, we’ll be setting it. Back on the Object Cloning window, click the Select Action dropdown and select the Set Text action.
    3. Click into the Text to Set field and press F2 to invoke the Insert Variables window. Select the vTranslatedText variable from the list and press the Insert button.
    4. Press Save to close the Object Cloning configuration window.
  38. Drag one final Object Cloning command from the Commands pane over to the bottom of the Actions List.
    1. Select the Automation Anywhere Labs – Translate – Google Chrome selection for the Select Window drop down, then left-click and hold the Capture button to begin an Object Clone.
    2. Hover the cursor over the exercise page’s Submit button until its border is flashing with a red outline, then release.
    3. Click the Select Action dropdown and select the Left Click action.
    4. Press Save to close the Object Cloning configuration window.
  39. Finally – time to test. Click the Save button with the blue disk icon at the top of the screen to save your bot and press the green Play button.
  40. The bot should launch Google Chrome automatically navigating to the exercise page, extract the Bulgarian text from the page, then you should see an IE window open up (which is the MetaBot we are interacting with), put the translated text into Bing Translate and pull back the English Version. Finally, the bot should enter the translated text into the exercise page’s field and submit. Assuming the bot ran successfully, you should get a message with the accuracy percentage and the total time taken. Like mentioned in previous labs, your processing time may be faster or slower based on a variety of factors (network speed, local machine specs, etc.) and shouldn’t be something to worry about if its off by a matter of seconds.


Recap

Nice work on completing this tutorial. We used some new commands we hadn’t used before and learned to integrate a Bot Store component into our own automation. Let’s walk through exactly what our bot is doing line by line as a brief recap.

Line 1: Opening our browser and automatically navigating to the exercise page.
Line 2: Object Cloning command to extract the Text to Decode line from the exercise page and storing its contents into our vExtractedText variable.
Line 3: Using Before-After String command to remove the Text to Decode: part of the text we extracted.
Line 4: Message Box to display our vExtractedText – notice that the line is in green – that’s because we’d commented this line out after our initial test. At this point we could safely delete such a line as we know the code until that point is working fine.
Line 5: Invoking the BingTranslator MetaBot from Bot Store to translate our text from Bulgarian to English. The MetaBot is then filling its output to our variable vTranslatedText.
Line 6: Object Cloning command to set the text of the exercise page’s input field.
Line 7: Object Cloning command to left click the Submit button on the exercise page.

Next Steps

You’re doing great so far. Our next challenge will introduce the downloading of a file, reading from a CSV, and filling multiple fields – including drop downs, radio buttons, check boxes, and input fields.

Want to practice a bit more with this page?

  • There are several different language translation bots on Bot Store, try re-creating this bot using a different Bot Store bot.
    • How does that change the speed?
    • What impact does that have on the exercise page’s accuracy?
    • Does the text of the translation change at all?