Add parameters to selection criteria for captured web elements

You can use the Find Web Element block to capture one or more elements on a web page. In many cases you just use the point and click capture tool in LEAPWORK, but sometimes you want to be able to select a web element based on some dynamic values. You can do this by opening the Web Editor (click the web element and select "Edit web element").

One example is, if you use a Find Web Element to select a specific article from a list of articles. One of the default selection strategies produced by LEAPWORK you can choose from, is to select the article by the title as shown below. In the example, the Find Web Element block will search for an "<article>" tag that starts with the text "Trade view / 26 minu".

If you want to be able to specify the title instead of always selecting the same, you replace the text ("Trade view / 26 minu") 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 you click Save, a new field is now added to the Find Web Element block which allows you to feed the article 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.

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 "<articles>" on the page. In this case I just deleted the text condition leaving me with just the "Self" + "article" condition, which means it will search for all articles tags on the page.

Clicking the "Validate" button will actually perform the search, and in this case it finds 10 matching elements. If you have multiple occurrences you can specify which one you would like to use by setting a value in the "Use occurrence" field below the conditions. If you e.g. specify "4", the fourth article 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.