Loop Through Tags with the Same Class

There are a couple of ways to set up a loop. The first way is the easiest if it is viable, and involves looping over tags that all share a class attribute.


Each div element has the attribute class="story"

Note Each div element has the attribute class="story".

To determine whether looping through tags with the same class is possible, find the elements in the HTML view. In the case shown above, it is possible to loop through the three div tags with the attribute class="story".

  1. Right-click the first tag and select Loop > For Tags with Class > story.

    This creates a For Each Tag Path step in the robot, which loops through all elements on the page with the given class.

  2. On the Loop step, use the arrows to ensure that the correct tags are included in the loop.

    There might be other tags on the page that you do not wish to include in the loop but that use the given class. These can be excluded from the loop with an easy fix.

  3. To exclude tags with the selected class, in the Action tab of the editor select Loop > For Each Tag Path.

    Review the HTML view.

    The For Each Tag Path has automatically included the entire page as the found tag.

  4. Change the found tag to force the robot to only loop through tags within another given tag.

    Once the loop has been successfully created, any steps added after the For Each Tag Path step is repeated for each iteration of the loop.

    Steps after the loop step are executed for each iteration.

    In the example above showing the robot view, the robot extracts two pieces of text, a title and a preview, and return those values, for each iteration of the loop.