Files
cypress/docs/source/api/commands/not.md
T
2017-06-24 15:54:35 -04:00

2.1 KiB

title, comments
title comments
not false

Filter DOM element(s) from a set of DOM elements.

{% note info %} Opposite of {% url .filter() filter %} {% endnote %}

Syntax

.not(selector)
.not(selector, options)

Usage

.not() requires being chained off another cy command that yields a DOM element or DOM elements.

{% fa fa-check-circle green %} Valid Usage

cy.get('input').not('.required') // Yield all inputs without class '.required'

{% fa fa-exclamation-triangle red %} Invalid Usage

cy.not('.icon')      // Errors, cannot be chained off 'cy'
cy.location().not()  // Errors, 'location' does not yield DOM element

Arguments

{% fa fa-angle-right %} selector (String selector)

A selector used to remove matching DOM elements.

{% fa fa-angle-right %} options (Object)

Pass in an options object to change the default behavior of .not().

Option Default Notes
log true Whether to display command in Command Log
timeout {% url defaultCommandTimeout configuration#Timeouts %} Total time to retry getting the element

Yields {% helper_icon yields %}

.not() yields the new DOM element(s) without the selector provided in the command's argument.

Timeout {% helper_icon timeout %}

.not() will continue to look for the element(s) for the duration of the {% url defaultCommandTimeout configuration#Timeouts %}.

Examples

Selector

Yield the elements that do not have class active.

cy.get('.left-nav>li').not('.active').should('not.have.class', 'active') // true

Command Log

Find all buttons that are not of type submit

cy.get('form').find('button').not('[type="submit"]')

The commands above will display in the command log as:

Command Log not

When clicking on not within the command log, the console outputs the following:

Console log not

See also

  • {% url .filter() filter %}