Sometimes you need your AskUI workflow to adapt to variations in your User Interface (UI) when it is executed. This includes for example popups that may or may not appear or small changes in your UI depending on the state of the system.
In an earlier blog post about Conditional Execution we showed you how to execute different AskUI instructions depending on the (non-)existence of an element.
But what if you want to check for the existence of multiple elements at once? You have to write multiple instructions, which is a tedious process.
This is why we implemented the convenience method expectAllExist()
which takes an array of descriptions and checks for their existence.
Prerequisites
- AskUI installed in version
>0.20.0
The API
The method expectAllExist()
takes an array of element specifications and returns an object with an accumulated boolean allExist
which is true
when all elements have been detected. And, second, the element specifications with an additional property exists
which is true
when the individual element has been detected.
We will demonstrate the capabilities of expectAllExist()
on our AskUI Practice Page. You can follow along if you like.
![](https://cdn.prod.website-files.com/6630f90ff7431b0c5b1bb0e7/66681319e24e956d4a0b5dd8_askui-practice-page-light-theme.png)
Example 1: Expect a Single Text Element
Let us start with the most common use case: Checking for the existence of a text element.
When you log the returned object it will look like this:
Now you can go ahead and do, or not do, something with the knowledge that it exists 😊.
Example 2: Expect a Complex Element with a Relation
The next thing we want to check is the button with the label CE that is right of the text %. We do it like this:
Example 3: Expect Multiple Elements
For the last example, you have to switch to the Register tab of the practice page.
![](https://cdn.prod.website-files.com/6630f90ff7431b0c5b1bb0e7/666813bf85d0b79168ddb86e_askui-practice-page-light-theme-register-tab.png)
We will check for the existence of the text Name:, the checkbox with the label Developer and last but not least the button with the label Submit that is below the text Profile.
Limitations
The new convenience method only works for elements of type text, button, checkbox, switch, textfield and element. Additionally it has a limitation for textfield when used in conjunction with a relation. Read below on what to pay attention to.
Unsupported Elements
We currently do not support the following element types: container, icon, image, otherElement, special and table.
Use only Relation for Switch, Checkbox, Textfield
Textfields, Switches and Checkboxes do not have a text label inside them naturally. Specifying a text property for these elements will lead to a not detected element. Please only the relation property as shown in the following example:
Conclusion
Expecting the existence of multiple elements can be a real drag if you do not use expectAllExist()
. This new convenience method will help you to write more maintainable AskUI workflows and also prevent RSI hopefully.
If you have questions or need support, do not hesitate to join our Outverse-Community.