{
  "doc": {
    "id": "api/commands/focused",
    "title": "focused | Cypress Documentation",
    "description": "Get the DOM element that is currently focused in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/focused.md",
    "version": "a8fd16711bdda4c7b5645b9717e588ae99ec2470",
    "updated_at": "2026-05-18T17:21:32.047Z",
    "headings": [
      {
        "id": "api/commands/focused#focused",
        "text": "focused",
        "level": 1
      },
      {
        "id": "api/commands/focused#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/focused#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/focused#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/focused#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/focused#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/focused#no-args",
        "text": "No Args",
        "level": 3
      },
      {
        "id": "api/commands/focused#get-the-element-that-is-focused",
        "text": "Get the element that is focused",
        "level": 4
      },
      {
        "id": "api/commands/focused#blur-the-element-with-focus",
        "text": "Blur the element with focus",
        "level": 4
      },
      {
        "id": "api/commands/focused#make-an-assertion-on-the-focused-element",
        "text": "Make an assertion on the focused element",
        "level": 4
      },
      {
        "id": "api/commands/focused#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/focused#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/focused#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/focused#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/focused#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/focused#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/focused#syntax",
      "doc_id": "api/commands/focused",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\ncy.focused()cy.focused(options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.focused() // Yields the element currently in focus\n```\n\n### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.focused()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.focused()` to resolve before [timing out](#Timeouts) |\n\n### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n*   `cy.focused()` yields the DOM element it found.\n*   `cy.focused()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/focused.json",
      "token_estimate": 140
    },
    {
      "id": "api/commands/focused#arguments",
      "doc_id": "api/commands/focused",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.focused()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.focused()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/focused.json",
      "token_estimate": 79
    },
    {
      "id": "api/commands/focused#examples",
      "doc_id": "api/commands/focused",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### No Args\n\n#### Get the element that is focused\n\n```\ncy.focused().then(($el) => {  // do something with $el})\n```\n\n#### Blur the element with focus\n\n```\ncy.focused().blur()\n```\n\n#### Make an assertion on the focused element\n\n```\ncy.focused().should('have.attr', 'name', 'username')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/focused.json",
      "token_estimate": 59
    },
    {
      "id": "api/commands/focused#no-args",
      "doc_id": "api/commands/focused",
      "heading": "No Args",
      "heading_level": 3,
      "content_markdown": "### No Args\n\n#### Get the element that is focused\n\n```\ncy.focused().then(($el) => {  // do something with $el})\n```\n\n#### Blur the element with focus\n\n```\ncy.focused().blur()\n```\n\n#### Make an assertion on the focused element\n\n```\ncy.focused().should('have.attr', 'name', 'username')\n```\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/focused.json",
      "token_estimate": 56
    },
    {
      "id": "api/commands/focused#rules",
      "doc_id": "api/commands/focused",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `cy.focused()` requires being chained off a command that yields DOM element(s).\n\n### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)\n\n*   `cy.focused()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until the element(s) [exist in the DOM](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Implicit-Assertions).\n*   `cy.focused()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.\n\n### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `cy.focused()` can time out waiting for the element(s) to [exist in the DOM](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Implicit-Assertions).\n*   `cy.focused()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/focused.json",
      "token_estimate": 105
    },
    {
      "id": "api/commands/focused#timeouts-learn-about-timeouts",
      "doc_id": "api/commands/focused",
      "heading": "Timeouts Learn about timeouts",
      "heading_level": 3,
      "content_markdown": "### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `cy.focused()` can time out waiting for the element(s) to [exist in the DOM](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Implicit-Assertions).\n*   `cy.focused()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "timeouts-learn-about-timeouts"
      ],
      "path": "/llm/json/chunked/api/commands/focused.json",
      "token_estimate": 41
    },
    {
      "id": "api/commands/focused#command-log",
      "doc_id": "api/commands/focused",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Make an assertion on the focused element_**\n\n```\ncy.focused().should('have.attr', 'name').and('eq', 'num')\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on the `focused` command within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/focused.json",
      "token_estimate": 53
    }
  ]
}