2.6 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| blur | true |
Make the DOM element found in the previous command lose focus.
The following events are fired during blur: focusout, blur
| Returns | the new DOM element(s) found by the command. |
| Timeout | cy.blur will retry for the duration of the defaultCommandTimeout |
cy.blur()
Blur the DOM element from the previous command.
Options
Pass in an options object to change the default behavior of cy.blur.
| Option | Default | Notes |
|---|---|---|
force |
false |
Forces blur, disables error checking prior to blur |
log |
true |
whether to display command in command log |
Usage
Blur the comment input.
// returns the same <textarea> for further chaining
cy.get("[name='comment']").type("Nice Product!").blur()
Options Usage
Blur the first input, ignoring whether the input is currently focused.
// returns the same <input> for further chaining
cy.get("input:first").blur({force: true})
Command Log
Blur a textarea after typing.
cy.get("[name='comment']").type("Nice Product!").blur()
The commands above will display in the command log as:
When clicking on the blur command within the command log, the console outputs the following:
Errors
cy.blur() can only be called when there is a currently focused element.
There is currently no specific element that has focus. If you want to ensure focus before blurring, try using cy.focus() on the element before cy.blur()
cy.blur() timed out because your browser did not receive any blur events. This is a known bug in Chrome when it is not the currently focused window.
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 executed.
cy.blur() can only be called on the focused element.
If you want to ensure focus on a specific element before blurring, try using cy.focus() on the element before cy.blur()