Is it possible to test the absence of a specific element?
  • 25 Aug 2023
  • 1 Minute to read
  • Contributors
  • Dark
    Light

Is it possible to test the absence of a specific element?

  • Dark
    Light

Article Summary

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?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.