Skip to content

Latest commit

 

History

History
94 lines (58 loc) · 1.78 KB

File metadata and controls

94 lines (58 loc) · 1.78 KB
title
focused

Get the DOM element that is currently focused.

Syntax

cy.focused()
cy.focused(options)

Usage

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

cy.focused()    // Yields the element currently in focus

Arguments

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

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

Option Default Description
log true {% usage_options log %}
timeout {% url defaultCommandTimeout configuration#Timeouts %} {% usage_options timeout cy.focused %}

Yields {% helper_icon yields %}

{% yields sets_dom_subject cy.focused %}

Examples

No Args

Get the element that is focused

cy.focused().then(($el) => {
  // do something with $el
})

Blur the element with focus

cy.focused().blur()

Make an assertion on the focused element

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

Rules

Requirements {% helper_icon requirements %}

{% requirements dom cy.focused %}

Assertions {% helper_icon assertions %}

{% assertions existence cy.focused %}

Timeouts {% helper_icon timeout %}

{% timeouts existence cy.focused %}

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:

{% imgTag /img/api/focused/make-assertion-about-focused-element.png "Command Log focused" %}

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

{% imgTag /img/api/focused/currently-focused-element-in-an-input.png "console focused" %}

See also

  • {% url .blur() blur %}
  • {% url .focus() focus %}