Pages where Each Page Links to Next

The other common way of linking pages together is shown below.

Each Page Links to Next

Here, each page simply links to the next page, typically with a link or form button named something like "Next".

To loop through such pages, use the Repeat action. The Repeat action will loop through the pages that are supplied to it by another action named Next. Watch the video below or read on to learn how.

Video demonstrating how to use the Repeat-Next loop.

The principle is as follows: The Repeat action must be given the first page as input. It will then loop through the pages, and in each iteration it will output a page. In each iteration, we can process the current page, and we must also give the Repeat action the next page using the Next action. If we don't give the Repeat action a new page, it will not provide another iteration, i.e. the loop will end.

This excerpt from a robot shows an example:

Here, like before, we are looping through the result pages from a search request, symbolized by the step named "(Submit Form)". The form submission step will output the first result page, which we give to the Repeat action. In the first branch from the Repeat action, we process the current page. In the second branch, we load the next page by clicking its link. The Next action will send the page back to the Repeat action, which will output it in its next iteration. When the last page is reached, the Click action will generate an error. Therefore, the "Click" step is configured to terminate the loop. In the "Click" step, this is done in the "Error Handling" tab by setting the "Then" property to "Break Loop". Please see How to Handle Errors for more information on this.

An alternative way of handling the last page is shown in the robot excerpt below:

To detect when the last page has been reached, we use a Test Tag action in the second branch. The Test Tag action checks that the page contains a next-page link, for example by looking for an <a>-tag containing the text "Next". If the page contains such a link, we load this page and give this to the Next action. When the last page is reached, the Test Tag action will stop execution down the second branch, and no new page will be given to the Repeat action, causing the loop to end.

Note that finding the link to the next page can be tricky. A common mistake is to find the previous-page link on some pages instead of the next-page link, because the layout of the pages changes slightly between the first page, the subsequent pages, and the last page. Another common mistake is to not detect the last page reliably. You may have to configure the tag finders of the steps carefully to make things work (see How to Use the Tag Finders).

When you are working with a robot in Design Studio, Design Studio may not always be able to step correctly back and forth between iterations of a Repeat action. If you are not sure whether Design Studio has got it right, click Refresh to update.