In some cases, asserting against the right element is a challenge. You may be asserting against an element that is very similar, or identical, to other elements on the page. Or the properties and attributes of an element have dynamically generated values. Or the element only briefly appears when you hover over a different element.
If you are unable to assert against the correct element using a recorded assertion step, here are some additional methods you can try.
If the assertion is targeting the wrong element, try adding Configure Find to specify which element attributes are the most important.
When you use Configure Find for an assertion, you must choose between auto-heal (default setting) or fail this step. Fail this step disables auto-heal.
For more information on how these settings affect "is present" and "is not present" assertions, click here.
If recording a regular assertion for an element proves to be difficult, another option is to convert an existing step that finds the element, such as a click step, into an assertion:
- Click on More actions (...) for the click step that you wish to convert.
- Select Assert on element from the dropdown.
- Set the criteria for your assertion.
- Click OK. The existing click step will have been converted into an assertion step.
You can use custom CSS queries or XPath IDs to identify the element you wish to assert against. To create a custom find assertion, take the following steps:
- Click on the plus symbol to add a new step.
- Select Find elements
- In the custom find view, you can use CSS or XPath to identify the element in the browser window.
- For the action, select Make assertion.
- When you click Next, you can set the criteria for your assertion in the element assertion menu.
Try Configure Find first
Before using CSS or XPath, we recommend trying to identify the correct element with Configure Find.
A native click assertion that uses Configure Find is easier to maintain, and a custom find assertion should only be used in cases where Configure Find does not include the attributes needed to correctly identify the element.
For an overview on identifying elements in mabl, read our documentation on finding the correct element.
Updated 13 days ago