MuleSoft RPA: Easily Iterate over HTML Data

Why Use MuleSoft RPA?

For the first blog post in our series “Solving Data Collection and Processing Challenges using Salesforce and MuleSoft RPA”, we’re addressing a common scenario, getting data from a web page or HTML.  Whether or not you are on the Salesforce platform, you will want to use MuleSoft RPA.  The speed, ease of use, feature set, and interoperability with other platforms make it the Go-To choice for us.

In many Use Cases we see with customers, there is a requirement to build Robotic Process Automations (RPA) that iterate over data of unknown length inside a Web browser or from a web page. Consider the scenario where a customer needs an automated process to find all Widget Names on an inventory Web page where Build Category = “Boom Box”. 

Sample Inventory Web Page for MuleSoft RPA Example
Widget data table

The process does not know how many records are going to be on the page during any specific RPA execution instance, nor does it care.  As long as it finds the Build Category that it is looking for, everything will work.

How to get it done.

To iterate over this data in MuleSoft RPA Builder, simply use a For Loop with a Managed Block inside of it which breaks out of the loop once an iteration is reached with no data found. To do this: 

  • Open a Web Session. Inside of this Web Session, add a Loop element with a very high number of iterations (more iterations than will be realistically encountered). Inside the Loop element: 
    • Place a Managed block 
    • Inside the DoAction section of the Managed block: 
      • Add a “Combine Strings” element to generate an XPath to the relevant data using the loop iteration number) 
      • Add a Get Web Element Text element which uses the prior-generated XPath to find the relevant data  
    • Inside the OnError section of the Managed block: 
      • Add a “Force OK State” element 
      • Add a “Break Loop” element 
      • Note: This “OnError” section of a Managed block is the equivalent of the “catch” section of a Try/Catch block in regular programming 
      • Note: This OnError section will get called the first time there is nothing found for the XPath defined in the DoAction section. So if there are 4 records, and the XPath looks for the 5th record, it will fail and the execution will flow into this OnError section. 


MuleSoft Activity Workflow Builder
Build your MuleSoft Workflow like this


In the above example, the Combine Strings element is configured as follows. Pattern = (//tr[td[text() = ‘Boom Box’]]/td[1])[{1}] (where {1} is the loop iteration) 

MuleSoft Activity Workflow COmbine Strings Wizard
Combine Strings Wizard

 Next, the Get Web Element Text element is configured as shown below, referencing “XPath to Widget Name.Combined String”: 

Get Web Element Text Wizard
Use the Get Web Element Text Wizard

Using this pattern and this Kickstarter, you can adapt the above approach as necessary for your use case.


While this is a very simple example, we have illustrated the power and potential of MuleSoft RPA.  With this article as a guide, it is simple to iterate over Web data tables of unknown length using MuleSoft RPA.  You can watch the video on YouTube here:

Talk to the Professionals!

To learn more about our MuleSoft or Salesforce services, please check out our website or fill out a Contact Us form here.

CloudFirst Labs logo