{
  "doc": {
    "id": "api/commands/get",
    "title": "get | Cypress Documentation",
    "description": "Get one or more DOM elements by selector or alias in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/get.md",
    "version": "3cf5b86b3403f604bdf7f3e35025c3bc3865e02c",
    "updated_at": "2026-05-07T17:44:31.931Z",
    "headings": [
      {
        "id": "api/commands/get#get",
        "text": "get",
        "level": 1
      },
      {
        "id": "api/commands/get#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/get#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/get#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/get#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/get#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/get#selector",
        "text": "Selector",
        "level": 3
      },
      {
        "id": "api/commands/get#get-the-input-element",
        "text": "Get the input element",
        "level": 4
      },
      {
        "id": "api/commands/get#find-the-first-li-descendent-within-a-ul",
        "text": "Find the first li descendent within a ul",
        "level": 4
      },
      {
        "id": "api/commands/get#find-the-dropdown-menu-and-click-it",
        "text": "Find the dropdown-menu and click it",
        "level": 4
      },
      {
        "id": "api/commands/get#find-5-elements-with-the-given-data-attribute",
        "text": "Find 5 elements with the given data attribute",
        "level": 4
      },
      {
        "id": "api/commands/get#find-the-link-with-an-href-attribute-containing-the-word-questions-and-click-it",
        "text": "Find the link with an href attribute containing the word \"questions\" and click it",
        "level": 4
      },
      {
        "id": "api/commands/get#find-the-element-with-id-that-starts-with-local",
        "text": "Find the element with id that starts with \"local-\"",
        "level": 4
      },
      {
        "id": "api/commands/get#find-the-element-with-id-that-ends-with-remote",
        "text": "Find the element with id that ends with \"-remote\"",
        "level": 4
      },
      {
        "id": "api/commands/get#find-the-element-with-id-that-starts-with-local-and-ends-with-remote",
        "text": "Find the element with id that starts with \"local-\" and ends with \"-remote\"",
        "level": 4
      },
      {
        "id": "api/commands/get#find-the-element-with-id-that-has-characters-used-in-css-like",
        "text": "Find the element with id that has characters used in CSS like \".\", \":\".",
        "level": 4
      },
      {
        "id": "api/commands/get#cy-get-in-the-within-command",
        "text": "cy.get() in the .within() command",
        "level": 3
      },
      {
        "id": "api/commands/get#get-vs-find",
        "text": "Get vs Find",
        "level": 3
      },
      {
        "id": "api/commands/get#alias",
        "text": "Alias",
        "level": 3
      },
      {
        "id": "api/commands/get#get-the-aliased-todos-elements",
        "text": "Get the aliased 'todos' elements",
        "level": 4
      },
      {
        "id": "api/commands/get#get-the-aliased-submitbtn-element",
        "text": "Get the aliased 'submitBtn' element",
        "level": 4
      },
      {
        "id": "api/commands/get#get-the-aliased-users-fixture",
        "text": "Get the aliased 'users' fixture",
        "level": 4
      },
      {
        "id": "api/commands/get#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/get#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/get#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/get#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/get#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/get#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/get#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/get#syntax",
      "doc_id": "api/commands/get",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\ncy.get(selector)cy.get(alias)cy.get(selector, options)cy.get(alias, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('.list > li') // Yield the <li>'s in .list\n```\n\n### Arguments\n\n**selector _(String selector)_**\n\nA selector used to filter matching DOM elements.\n\n**alias _(String)_**\n\nAn alias as defined using the [`.as()`](/llm/markdown/api/commands/as.md) command and referenced with the `@` character and the name of the alias.\n\nYou can use `cy.get()` for aliases of primitives, regular objects, or even DOM elements.\n\nWhen using aliases with DOM elements, Cypress will query the DOM again if the previously aliased DOM element has gone stale.\n\n**Core Concept**\n\n[You can read more about aliasing objects and elements in our Core Concept Guide](/llm/markdown/app/core-concepts/variables-and-aliases.md#Aliases).\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.get()`.\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| `withinSubject` | null | Element to search for children in. If null, search begins from root-level DOM element |\n| `includeShadowDom` | [`includeShadowDom` config option value](/llm/markdown/app/references/configuration.md#Global) | Whether to traverse shadow DOM boundaries and include elements within the shadow DOM in the yielded results. |\n\n### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n*   `cy.get()` yields the DOM element(s) it found, or the results of the alias lookup.\n*   `cy.get()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 327
    },
    {
      "id": "api/commands/get#arguments",
      "doc_id": "api/commands/get",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**selector _(String selector)_**\n\nA selector used to filter matching DOM elements.\n\n**alias _(String)_**\n\nAn alias as defined using the [`.as()`](/llm/markdown/api/commands/as.md) command and referenced with the `@` character and the name of the alias.\n\nYou can use `cy.get()` for aliases of primitives, regular objects, or even DOM elements.\n\nWhen using aliases with DOM elements, Cypress will query the DOM again if the previously aliased DOM element has gone stale.\n\n**Core Concept**\n\n[You can read more about aliasing objects and elements in our Core Concept Guide](/llm/markdown/app/core-concepts/variables-and-aliases.md#Aliases).\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.get()`.\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| `withinSubject` | null | Element to search for children in. If null, search begins from root-level DOM element |\n| `includeShadowDom` | [`includeShadowDom` config option value](/llm/markdown/app/references/configuration.md#Global) | Whether to traverse shadow DOM boundaries and include elements within the shadow DOM in the yielded results. |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 252
    },
    {
      "id": "api/commands/get#yields-learn-about-subject-management",
      "doc_id": "api/commands/get",
      "heading": "Yields Learn about subject management",
      "heading_level": 3,
      "content_markdown": "### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n*   `cy.get()` yields the DOM element(s) it found, or the results of the alias lookup.\n*   `cy.get()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "yields-learn-about-subject-management"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 45
    },
    {
      "id": "api/commands/get#examples",
      "doc_id": "api/commands/get",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### Selector\n\n#### Get the input element\n\n```\ncy.get('input').should('be.disabled')\n```\n\n#### Find the first `li` descendent within a `ul`\n\n```\ncy.get('ul li:first').should('have.class', 'active')\n```\n\n#### Find the dropdown-menu and click it\n\n```\ncy.get('.dropdown-menu').click()\n```\n\n#### Find 5 elements with the given data attribute\n\n```\ncy.get('[data-test-id=\"test-example\"]').should('have.length', 5)\n```\n\n#### Find the link with an href attribute containing the word \"questions\" and click it\n\n```\ncy.get('a[href*=\"questions\"]').click()\n```\n\n#### Find the element with id that starts with \"local-\"\n\n```\ncy.get('[id^=local-]')\n```\n\n#### Find the element with id that ends with \"-remote\"\n\n```\ncy.get('[id$=-remote]')\n```\n\n#### Find the element with id that starts with \"local-\" and ends with \"-remote\"\n\n```\ncy.get('[id^=local-][id$=-remote]')\n```\n\n#### Find the element with id that has characters used in CSS like \".\", \":\".\n\n```\ncy.get('#id\\\\.\\\\.\\\\.1234') // escape the character with \\\\\n```\n\n### `cy.get()` in the [`.within()`](/llm/markdown/api/commands/within.md) command\n\nSince `cy.get()` is chained off of `cy`, it always looks for the selector within the entire `document`. The only exception is when used inside a [.within()](/llm/markdown/api/commands/within.md) command.\n\n```\ncy.get('form').within(() => {  cy.get('input').type('Pamela') // Only yield inputs within form  cy.get('textarea').type('is a developer') // Only yield textareas within form})\n```\n\n### Get vs Find\n\nThe `cy.get` command always starts its search from the [cy.root](/llm/markdown/api/commands/root.md) element. In most cases, it is the `document` element, unless used inside the [.within()](/llm/markdown/api/commands/within.md) command. The [.find](/llm/markdown/api/commands/find.md) command starts its search from the current subject.\n\n```\n<div class=\"test-title\">cy.get vs .find</div><section id=\"comparison\">  <div class=\"feature\">Both are querying commands</div></section>\n```\n\n```\ncy.get('#comparison')  .get('div')  // finds the div.test-title outside the #comparison  // and the div.feature inside  .should('have.class', 'test-title')  .and('have.class', 'feature')cy.get('#comparison')  .find('div')  // the search is limited to the tree at #comparison element  // so it finds div.feature only  .should('have.length', 1)  .and('have.class', 'feature')\n```\n\n### Alias\n\nFor a detailed explanation of aliasing, [read more about aliasing here](/llm/markdown/app/core-concepts/variables-and-aliases.md#Aliases).\n\n#### Get the aliased 'todos' elements\n\n```\ncy.get('ul#todos').as('todos')//...hack hack hack...//later retrieve the todoscy.get('@todos')\n```\n\n#### Get the aliased 'submitBtn' element\n\n```\nbeforeEach(() => {  cy.get('button[type=submit]').as('submitBtn')})it('disables on click', () => {  cy.get('@submitBtn').should('be.disabled')})\n```\n\n#### Get the aliased 'users' fixture\n\n```\nbeforeEach(() => {  cy.fixture('users.json').as('users')})it('disables on click', () => {  // access the array of users  cy.get('@users').then((users) => {    // get the first user    const user = users[0]    cy.get('header').contains(user.name)  })})\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 484
    },
    {
      "id": "api/commands/get#selector",
      "doc_id": "api/commands/get",
      "heading": "Selector",
      "heading_level": 3,
      "content_markdown": "### Selector\n\n#### Get the input element\n\n```\ncy.get('input').should('be.disabled')\n```\n\n#### Find the first `li` descendent within a `ul`\n\n```\ncy.get('ul li:first').should('have.class', 'active')\n```\n\n#### Find the dropdown-menu and click it\n\n```\ncy.get('.dropdown-menu').click()\n```\n\n#### Find 5 elements with the given data attribute\n\n```\ncy.get('[data-test-id=\"test-example\"]').should('have.length', 5)\n```\n\n#### Find the link with an href attribute containing the word \"questions\" and click it\n\n```\ncy.get('a[href*=\"questions\"]').click()\n```\n\n#### Find the element with id that starts with \"local-\"\n\n```\ncy.get('[id^=local-]')\n```\n\n#### Find the element with id that ends with \"-remote\"\n\n```\ncy.get('[id$=-remote]')\n```\n\n#### Find the element with id that starts with \"local-\" and ends with \"-remote\"\n\n```\ncy.get('[id^=local-][id$=-remote]')\n```\n\n#### Find the element with id that has characters used in CSS like \".\", \":\".\n\n```\ncy.get('#id\\\\.\\\\.\\\\.1234') // escape the character with \\\\\n```\n",
      "section": "api",
      "anchors": [
        "selector"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 176
    },
    {
      "id": "api/commands/get#cy-get-in-the-within-command",
      "doc_id": "api/commands/get",
      "heading": "cy.get() in the .within() command",
      "heading_level": 3,
      "content_markdown": "### `cy.get()` in the [`.within()`](/llm/markdown/api/commands/within.md) command\n\nSince `cy.get()` is chained off of `cy`, it always looks for the selector within the entire `document`. The only exception is when used inside a [.within()](/llm/markdown/api/commands/within.md) command.\n\n```\ncy.get('form').within(() => {  cy.get('input').type('Pamela') // Only yield inputs within form  cy.get('textarea').type('is a developer') // Only yield textareas within form})\n```\n",
      "section": "api",
      "anchors": [
        "cy-get-in-the-within-command"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 72
    },
    {
      "id": "api/commands/get#get-vs-find",
      "doc_id": "api/commands/get",
      "heading": "Get vs Find",
      "heading_level": 3,
      "content_markdown": "### Get vs Find\n\nThe `cy.get` command always starts its search from the [cy.root](/llm/markdown/api/commands/root.md) element. In most cases, it is the `document` element, unless used inside the [.within()](/llm/markdown/api/commands/within.md) command. The [.find](/llm/markdown/api/commands/find.md) command starts its search from the current subject.\n\n```\n<div class=\"test-title\">cy.get vs .find</div><section id=\"comparison\">  <div class=\"feature\">Both are querying commands</div></section>\n```\n\n```\ncy.get('#comparison')  .get('div')  // finds the div.test-title outside the #comparison  // and the div.feature inside  .should('have.class', 'test-title')  .and('have.class', 'feature')cy.get('#comparison')  .find('div')  // the search is limited to the tree at #comparison element  // so it finds div.feature only  .should('have.length', 1)  .and('have.class', 'feature')\n```\n",
      "section": "api",
      "anchors": [
        "get-vs-find"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 124
    },
    {
      "id": "api/commands/get#alias",
      "doc_id": "api/commands/get",
      "heading": "Alias",
      "heading_level": 3,
      "content_markdown": "### Alias\n\nFor a detailed explanation of aliasing, [read more about aliasing here](/llm/markdown/app/core-concepts/variables-and-aliases.md#Aliases).\n\n#### Get the aliased 'todos' elements\n\n```\ncy.get('ul#todos').as('todos')//...hack hack hack...//later retrieve the todoscy.get('@todos')\n```\n\n#### Get the aliased 'submitBtn' element\n\n```\nbeforeEach(() => {  cy.get('button[type=submit]').as('submitBtn')})it('disables on click', () => {  cy.get('@submitBtn').should('be.disabled')})\n```\n\n#### Get the aliased 'users' fixture\n\n```\nbeforeEach(() => {  cy.fixture('users.json').as('users')})it('disables on click', () => {  // access the array of users  cy.get('@users').then((users) => {    // get the first user    const user = users[0]    cy.get('header').contains(user.name)  })})\n```\n",
      "section": "api",
      "anchors": [
        "alias"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 109
    },
    {
      "id": "api/commands/get#get-the-aliased-users-fixture",
      "doc_id": "api/commands/get",
      "heading": "Get the aliased 'users' fixture",
      "heading_level": 4,
      "content_markdown": "#### Get the aliased 'users' fixture\n\n```\nbeforeEach(() => {  cy.fixture('users.json').as('users')})it('disables on click', () => {  // access the array of users  cy.get('@users').then((users) => {    // get the first user    const user = users[0]    cy.get('header').contains(user.name)  })})\n```\n",
      "section": "api",
      "anchors": [
        "get-the-aliased-users-fixture"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 49
    },
    {
      "id": "api/commands/get#rules",
      "doc_id": "api/commands/get",
      "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.get()` 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.get()` 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.get()` 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.get()` 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.get()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 105
    },
    {
      "id": "api/commands/get#timeouts-learn-about-timeouts",
      "doc_id": "api/commands/get",
      "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.get()` 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.get()` 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/get.json",
      "token_estimate": 41
    },
    {
      "id": "api/commands/get#command-log",
      "doc_id": "api/commands/get",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Get an input and assert on the value_**\n\n```\ncy.get('input[name=\"firstName\"]').should('have.value', 'Homer')\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on the `get` command within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/get.json",
      "token_estimate": 53
    }
  ]
}