- Print
- DarkLight
Is it possible to test the absence of a specific element?
Article summary
Did you find this summary helpful?
Thank you for your feedback
There are several ways to check that a certain element is not found.
If the target is a string
You can use the standard assertion command.
Please click here for further information.
If the target does not have a string
If you want to check that an element does not exist on a page
You can use a [JS Step].
var selector = "<TODO: REPLACE SELECTOR>"; //Please replace
var element = document.querySelector(selector);
if (element) {
throw new Error('Error: There is an element that shouldn’t exist (' + selector + ').');
}
Was this article helpful?