Looping 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 which all share a class attribute.

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

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

The easiest way to create the loop, is to right click the first tag and select to Loop For Tags With Class as shown below.

Right clicking to insert a step which loops through all 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. Use the arrows on the loop step to ensure that the correct tags are included in the loop. There might be other tags on the page that you don't wish to include in the loop but which use the given class. These can often be excluded from the loop with an easy fix. Click on the For Each Tag Path step and take a look at the HTML view. As shown below the For Each Tag Path has automatically included the entire page as the found tag.

Limit the tags which the For Each Tag Path step loops through. Notice the tag with class="story" near the top of the page. It is being purposefully excluded from the loop.

However, by changing the found tag, it is possible 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 will be repeated for each iteration of the loop.

Steps after the loop step will be executed for each iteration.

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