Element assertion FAQs
Commonly asked questions about element assertions
- Can I assert that an element is not on the page?
- Can I assert against an element that only appears on hover?
- Can I assert against an SVG element?
- Can I assert against CSS properties?
- Can I assert that a page or image has fully loaded?
- Can I assert that the date is the current day?
Can I assert that an element is not on the page?
If you want to assert that an element does not exist on the page, depending on the circumstances, you can take one of the following approaches:
- Work backwards: Create an "is not present" assertion while the element is still on the page. The assertion runs after being created and fails. Move the step to the position in your test where you expect it to be absent. See an example of this strategy in the following animation.

Working backwards to create an "is not present" assertion
- Use a custom find assertion: If the element doesn't appear during testing, but you can identify it with CSS or XPath, you can record a custom find assertion and select the "is not present" assertion type.
Can I assert against an element that only appears on hover?
If the element only appears briefly or disappears when you try to record an assertion step, consider trying one of the following workarounds:
- If the tooltip is clickable, record a click step on the tooltip and convert that step into an assertion using assert on element
- If you are familiar with CSS or XPath selectors, you can try creating a custom find assertion.
Can I assert against an SVG element?
Yes, the mabl Trainer can record clicks and assertions against <svg>
elements and elements within an SVG.
Note
The mabl Trainer cannot record clicks or assertions on specific coordinates within
<path>
elements.
Can I assert against CSS properties?
Yes, the mabl Trainer supports CSS assertions. When creating an element assertion, click on the "CSS" tab to select the property that you want to assert against.
If you are asserting against anything measured in px on the page, keep in mind the following considerations:
- Different browsers handle relative sizing slightly differently. Anything measured in
px
, such asheight
,width
, orborder-top
, may return slightly different values when run across different browsers. In this situation, we suggest using two CSS assertions - one using the “greater than” assertion type and one using the “less than” assertion type - to specify an acceptable range for your elements. - Your application may size elements differently depending on your viewport. If you want to assert against
height
,width
,border-top
, or any other property that is measured inpx
, set the viewport size before running your assertion. Otherwise you may get inconsistent values during your assertions.
Limitation
CSS assertions against images are not supported.
Can I assert that a page or image has fully loaded?
There is no direct way to assert whether a page or image has fully loaded. One workaround is to assert on an element, element property, or element attribute that consistently indicates that the page or image is fully loaded. Ultimately, it depends on how your page works
Can I assert that the date is the current day?
If an application shows the current date in a specific format, you can create an assertion with some help from JavaScript. See our guide on working with dates in mabl for more information.
Updated about 2 months ago