Skip to main content

Convert currency in a browser

We will build a flow that uses Google search to convert a dollar amount to euros: it asks you for a number, searches for the conversion, scrapes the answer off the results page and shows it in a dialog.

Create Flow

  1. Open the Designer and click Create New Project.

    New Project

  2. Name it and press Create New Project.

    New Project Name

    The project name sits in the top bar next to the branch selector; clicking it is how you move between projects later.

    Project bar

  3. Build the flow by dragging nodes from the palette, or by right-clicking the empty canvas and searching by name.

    Flow

    The nodes used, in order:

    NodeWhat it does here
    Trigger → InjectStarts the flow
    Dialog → Input BoxAsks for the dollar amount
    Browser → Open BrowserLaunches Chrome
    Programming → FunctionBuilds the Google search URL
    Browser → Open LinkNavigates to it
    Browser → Get ValueReads the converted amount off the page
    Dialog → Message BoxShows the result
    Flow → StopEnds the flow
    note

    The default node names are kept here, but renaming them pays off on anything larger. "Get Value" says what the node is; "Read Converted Amount" says what it is for.

  4. Click the Input Box node and set its properties. The Output is the important half — whatever the user types lands in msg.amount.

    Input Box

  5. Click the Function node, open its editor, and paste:

    var q = msg.amount + "+dollar+to+euro";
    msg.link = "https://www.google.com/search?q=" + q;
    return msg;

    This is the whole trick of the flow: a search query is just a URL with the question in it.

  6. Click Open Link and point the URL at the link the function built.

    Url

  7. Click Get Value and set the Selector.

    Selector

    Here is the copyable version:

    //*[@data-value]
    Selectors on someone else's page

    That XPath describes Google's markup on the day this was written, and Google is free to change it. If the flow starts returning nothing, check the selector first — the Inspect tool is how you find a new one.

  8. Click Message Box and set the text to the value you just scraped.

    Message Box

  9. Save with the save icon, or Ctrl+S.

    Save

Run Flow

  1. Press the play icon on the canvas toolbar and choose where to run.

    Play Icon

    Local runs on a robot connected to your own machine; Cloud runs on Robomotion's infrastructure. Choose Local here, so you can watch the browser work.

    note

    Local is only available if you have a robot connected. If you have not set one up, follow install a robot and then connect it.

  2. An input box appears on your desktop. Enter an amount and press OK.

    Input Box

  3. The browser the flow started loads the Google results.

    Google Result Page

  4. A message box shows the value the flow scraped.

    Result Message Box

    The flow is paused at the Message Box while that dialog is on screen — the browser stays open until you click OK. That is worth remembering: a dialog on an unattended robot waits forever, because nobody is there to dismiss it.

Try changing it

  • Loop it. Feed a list of amounts to a For Each and convert them all in one run.
  • Drop the dialogs. Replace the Input Box with a fixed value and the Message Box with a Debug node, and the flow can run unattended.
  • Add a Catch so a changed selector reports a real error instead of a blank result.