title |
---|
not |
Filter DOM element(s) from a set of DOM elements.
{% note info %}
Opposite of {% url .filter()
filter %}
{% endnote %}
{% note info %}
The querying behavior of this command matches exactly how {% url .not()
http://api.jquery.com/not %} works in jQuery.
{% endnote %}
.not(selector)
.not(selector, options)
{% fa fa-check-circle green %} Correct Usage
cy.get('input').not('.required') // Yield all inputs without class '.required'
{% fa fa-exclamation-triangle red %} Incorrect Usage
cy.not('.icon') // Errors, cannot be chained off 'cy'
cy.location().not() // Errors, 'location' does not yield DOM element
{% 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 | Description |
---|---|---|
log |
true |
{% usage_options log %} |
timeout |
{% url defaultCommandTimeout configuration#Timeouts %} |
{% usage_options timeout .not %} |
{% yields changes_dom_subject_or_subjects .not %}
<ul>
<li>Home</li>
<li class='active'>About</li>
<li>Services</li>
<li>Pricing</li>
<li>Contact</li>
</ul>
cy.get('ul>li').not('.active').should('have.length', 4) // true
{% requirements dom .not %}
{% assertions existence .not %}
{% timeouts existence .not %}
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:
{% imgTag /img/api/not/filter-elements-with-not-and-optional-selector.png "Command Log not" %}
When clicking on not
within the command log, the console outputs the following:
{% imgTag /img/api/not/log-elements-found-when-using-cy-not.png "Console Log not" %}
- {% url
.filter()
filter %}