Files
cypress/docs/source/api/commands/focused.md
T
2017-05-23 17:17:27 -04:00

1.5 KiB

title, comments, description
title comments description
focused true

Get the DOM element that is currently focused.

Returns the current DOM element that is focused or null
Timeout cy.focused will retry for the duration of the defaultCommandTimeout

cy.focused()

Get the focused DOM element.

Options

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

cy.focused( options )

Option Default Notes
log true whether to display command in command log

Usage

Get the element that is focused.

cy.focused()

Make an assertion on the focused element.

cy.focused().should('have.attr', 'name', 'username')

Command Log

Make an assertion on the focused element.

cy.focused().should('have.attr', 'name').and('eq', 'num')

The commands above will display in the command log as:

screen shot 2015-11-27 at 1 01 51 pm

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

screen shot 2015-11-27 at 1 02 02 pm

See also