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:
1. By changing the 'Use Occur' property of the respective building block to 'All'
User can change the 'Use Occur' property to 'All' for the supporting building blocks in Web Automation/Desktop UI and Image and Text cases. It means that it will execute the respective block for the defined number of times until the condition inside is TRUE. For e.g
We have to read all the values inside the below drop down:
As shown above, first we need to make dynamic strategy where it identifies all the elements and then use the 'Use Occur' property as 'All' 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.
This green output connector triggers when the iteration of all occurrences are completed.
When the above script is executed, the result is as shown below:
Blocks which support 'Use Occur' feature are:
Data-Driven & Logic
Find And Get
Mouse And Keyboard
2. Using Loop block explicitly
Loop functionality can be used externally with the help of Loop building block.
For instance, the above example of selecting the drop-down menu items can be achieved using 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.
Strategy Editor for Find Web Element:
For any clarification, please contact our Priority Support.