Leapwork Strategy Editor has the capability to capture one or more elements on a web page. In many cases, users are looking to make dynamic strategies so as to capture multiple elements in one go.
Wildcards are special symbols and Leapwork supports one standard wildcard: the asterisk (*).The asterisk wildcard corresponds to a string of any length (including an empty string), representing any continuous string of zero or more characters of any type allowing for flexibility in occurrences matching.
Tokens can be used to input a value in the Strategy editor. The strategy can be made dynamic by using the below ways-
Using Tokens :
If the user uses a Find Web Element block to select a specific element from a list of elements. One of the default selection strategies produced by Leapwork users can choose from, is to select the element by the title as shown below.
In the example, the Find Web Element block will search for an "<anchor>" tag that is equal to the text "A/B Testing".
If users want to be able to specify the title dynamically instead of always selecting the same static element, we replace the text ("A/B Testing") with a FIELD. Just delete the text and right-click in the field, select "Insert token" + "Add new field".
This will add a FIELD token into the field. When we click on Save, a new field is now added to the Find Web Element block which allows us to feed the title when the test runs. In the example below, we are using a Set Text block to define the article title to search for, but the value could come from any building block in the flow or from a variable, any database, or from an Excel file.
Another way of using dynamic fields in the selection criteria is to specify which occurrence to search for. Using the same example as above, we can modify the selection strategy to search for all "<anchor>" on the page. In this case, we will delete the text condition and it will leave us with just the "Self" + "anchor" condition, which means it will search for all anchor tags on the page.
Clicking the "Validate" button will actually perform the search, and in this case, it finds 46 matching elements. If we have multiple occurrences we can specify which one we would like to use by setting a value in the "Use occurrence" field below the conditions. If we e.g. specify "4", the fourth anchor tag found will be returned.
Just as with the text condition previously we can also add a FIELD to the occurrence field. Just right-click and add the field as before.
Clicking Save will add this to the building block allowing us to specify exactly which occurrence we want to use. In the example below, we have used a Set Number block to specify which occurrence to use.
In the below example, the Find Web Element block will search for an "<anchor>" tag that is equal to the text "A/B Testing".
If we want to be able to specify the title dynamically instead of using tokens, we need to replace the text ("A/B Testing") with a Wildcard. Just delete the text and right-click in the field, select "Insert token" + Add Wildcard(*)
If we click on the Validate button then it will return 45 anchor tags in this case without passing the value from any other block as we used to do while using tokens.
For any clarification, please contact our Priority Support.