Like any other programming language in LEAPWORK, a Loop block is used to perform a certain operation(s) for a specific number of times or until a condition is true.
It can be used in two ways:
By changing the 'Use Occur' property of the respective building block to 'All'.
Using the 'Loop' building block explicitly.
The detailed explanation is given below:
By changing the 'Use Occur' property of the respective building block to 'All'
Users can change the 'Use Occur' property to 'All' for the supporting building blocks in Web Automation, Desktop UI, and Image and Text use cases. This means that LEAPWORK will execute the respective block for the defined number of times until the condition inside is TRUE. For example, it has read all of the values inside the below drop-down:
The Script Used:
As shown above, first we need to make a dynamic strategy where it identifies all the elements, then set the 'Use Occur' property to 'All' in order to find all the elements and read related text using Get Web Text block.
Select which occurrence of the web element to use, if more than one is found.
Select “All” to iterate through all of the occurrences. By selecting “All”, the sub-properties ‘Current index’ and ‘Completed’ are shown (see below).
The current index when iterating through all occurrences of the web element. For instance, if three occurrences of a div tag are found, this property will contain 1 for the first one, then 2 for the second, and finally 3 for the last one.
The green output connector triggers when the iterations of all occurrences are completed.
When the above script is executed, the result is as shown below:
Blocks that support the 'Use Occur' feature are:
Data-Driven & Logic
Find And Get
Mouse And Keyboard
2. Using the Loop block explicitly
Loop functionality can be used externally with the help of the Loop building block.
For instance, the above example of selecting the drop-down menu items can be achieved using the Loop block as well.
Note: The current value of the Loop block is passed to the Use Occur property of Find Web Element in the Strategy Editor to find the menu items at runtime.
The Strategy Editor for Find Web Element:
For any clarification, please contact our Priority Support.