title |
---|
focused |
Get the DOM element that is currently focused.
cy.focused()
cy.focused(options)
{% fa fa-check-circle green %} Correct Usage
cy.focused() // Yields the element currently in focus
{% 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 sets_dom_subject cy.focused %}
cy.focused().then(($el) => {
// do something with $el
})
cy.focused().blur()
cy.focused().should('have.attr', 'name', 'username')
{% requirements dom cy.focused %}
{% assertions existence cy.focused %}
{% timeouts existence cy.focused %}
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" %}
- {% url
.blur()
blur %} - {% url
.focus()
focus %}