{
  "doc": {
    "id": "api/commands/shadow",
    "title": "shadow | Cypress Documentation",
    "description": "Traverse into the shadow DOM of an element in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/shadow.md",
    "version": "3cf5b86b3403f604bdf7f3e35025c3bc3865e02c",
    "updated_at": "2026-05-07T17:44:31.931Z",
    "headings": [
      {
        "id": "api/commands/shadow#shadow",
        "text": "shadow",
        "level": 1
      },
      {
        "id": "api/commands/shadow#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/shadow#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/shadow#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/shadow#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/shadow#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/shadow#find-and-click-on-a-button-inside-the-shadow-dom",
        "text": "Find and click on a button inside the shadow DOM",
        "level": 3
      },
      {
        "id": "api/commands/shadow#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/shadow#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/shadow#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/shadow#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/shadow#known-issue",
        "text": "Known Issue",
        "level": 2
      },
      {
        "id": "api/commands/shadow#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/shadow#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/shadow#syntax",
      "doc_id": "api/commands/shadow",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.shadow().shadow(options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('.shadow-host').shadow()\n```\n\n**Incorrect Usage**\n\n```\ncy.shadow() // Errors, cannot be chained off 'cy'cy.exec('npm start').shadow() // Errors, 'exec' does not yield DOM elementcy.get('.not-a-shadow-host').shadow() // Errors, subject must host a shadow root\n```\n\n### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.shadow()`.\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.get()` 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*   `.shadow()` yields the new DOM element(s) it found.\n*   `.shadow()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/shadow.json",
      "token_estimate": 171
    },
    {
      "id": "api/commands/shadow#usage",
      "doc_id": "api/commands/shadow",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('.shadow-host').shadow()\n```\n\n**Incorrect Usage**\n\n```\ncy.shadow() // Errors, cannot be chained off 'cy'cy.exec('npm start').shadow() // Errors, 'exec' does not yield DOM elementcy.get('.not-a-shadow-host').shadow() // Errors, subject must host a shadow root\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/shadow.json",
      "token_estimate": 48
    },
    {
      "id": "api/commands/shadow#arguments",
      "doc_id": "api/commands/shadow",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.shadow()`.\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.get()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/shadow.json",
      "token_estimate": 79
    },
    {
      "id": "api/commands/shadow#rules",
      "doc_id": "api/commands/shadow",
      "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*   `.shadow()` requires being chained off a command that yields a DOM element that is a shadow host (i.e. has a shadow root directly attached to it).\n\n### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)\n\n*   `.shadow()` 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*   `.shadow()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until the element(s) host(s) a shadow root.\n*   `.shadow()` 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*   `.shadow()` 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*   `.shadow()` can time out waiting for the element(s) to host a shadow root.\n*   `.shadow()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/shadow.json",
      "token_estimate": 160
    },
    {
      "id": "api/commands/shadow#requirements-learn-about-chaining-commands",
      "doc_id": "api/commands/shadow",
      "heading": "Requirements Learn about chaining commands",
      "heading_level": 3,
      "content_markdown": "### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `.shadow()` requires being chained off a command that yields a DOM element that is a shadow host (i.e. has a shadow root directly attached to it).\n",
      "section": "api",
      "anchors": [
        "requirements-learn-about-chaining-commands"
      ],
      "path": "/llm/json/chunked/api/commands/shadow.json",
      "token_estimate": 44
    },
    {
      "id": "api/commands/shadow#assertions-learn-about-assertions",
      "doc_id": "api/commands/shadow",
      "heading": "Assertions Learn about assertions",
      "heading_level": 3,
      "content_markdown": "### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)\n\n*   `.shadow()` 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*   `.shadow()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until the element(s) host(s) a shadow root.\n*   `.shadow()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.\n",
      "section": "api",
      "anchors": [
        "assertions-learn-about-assertions"
      ],
      "path": "/llm/json/chunked/api/commands/shadow.json",
      "token_estimate": 53
    },
    {
      "id": "api/commands/shadow#timeouts-learn-about-timeouts",
      "doc_id": "api/commands/shadow",
      "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*   `.shadow()` 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*   `.shadow()` can time out waiting for the element(s) to host a shadow root.\n*   `.shadow()` 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/shadow.json",
      "token_estimate": 60
    },
    {
      "id": "api/commands/shadow#known-issue",
      "doc_id": "api/commands/shadow",
      "heading": "Known Issue",
      "heading_level": 2,
      "content_markdown": "## Known Issue\n\nWhen working with `cy.click()`, it sometimes won't click the right element in Chrome. It's happening because of [the ambiguity in spec](https://bugs.chromium.org/p/chromium/issues/detail?id=1188919&q=shadowRoot%20elementFromPoint&can=2).\n\nIn this case, pass `'top'` to `cy.click()` like below:\n\n```\ncy.get('#element').shadow().find('[data-test-id=\"my-button\"]').click('top')\n```\n",
      "section": "api",
      "anchors": [
        "known-issue"
      ],
      "path": "/llm/json/chunked/api/commands/shadow.json",
      "token_estimate": 48
    },
    {
      "id": "api/commands/shadow#command-log",
      "doc_id": "api/commands/shadow",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Traverse into the shadow DOM of an element_**\n\n```\ncy.get('.shadow-host').shadow()\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on the `shadow` command within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/shadow.json",
      "token_estimate": 52
    }
  ]
}