Files
cypress/docs/source/api/commands/blur.md
T
2017-06-26 01:05:20 -04:00

2.5 KiB

title, comments
title comments
blur false

Blur a focused element.

Syntax

.blur()
.blur(options)

Usage

.blur() requires being chained off another cy command that yields a DOM element.

This element must currently be in focus. If you want to ensure an element is focused before blurring, try using {% url .focus() focus %} before .blur().

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

cy.get('[type="email"]').type('me@email.com').blur() // Blur email input
cy.get('[tabindex="1"]').focus().blur()              // Blur el with tabindex

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

cy.blur('input')              // Errors, cannot be chained off 'cy'
cy.window().blur()            // Errors, 'window' does not yield DOM element

Arguments

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

Pass in an options object to change the default behavior of .blur.

Option Default Description
log true {% usage_options log %}
force false Forces the action, disables checking if element is focused
timeout {% url defaultCommandTimeout configuration#Timeouts %} {% usage_options timeout .blur %}

Yields {% helper_icon yields %}

{% yields same_subject .blur %}

Requirements {% helper_icon defaultAssertion %}

{% requirements blurability .blur %}

Timeouts {% helper_icon timeout %}

{% timeouts assertions .blur %}

Examples

Blur

Blur the comment input.

cy.get('[name="comment"]').type('Nice Product!').blur()

Options

Blur the first input

Setting force to true in the options disables checking whether the input is focusable or currently has focus.

cy.get('input:first').blur({ force: true })

Notes

.blur() can time out because your browser did not receive any blur events.

If you see this error, you may want to ensure that the main browser window is currently focused. This means not being focused in debugger or any other window when the command is run.

Command Log

Blur a textarea after typing.

cy.get('[name="comment"]').focus().type('Nice Product!').blur()

The commands above will display in the command log as:

command log for blur

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

console.log for blur

See also

  • {% url .focus() focus %}
  • {% url cy.focused() focused %}