{
  "doc": {
    "id": "api/commands/eq",
    "title": "cy.eq()",
    "description": "Get a DOM element at a specific index within a set of DOM elements in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/eq.md",
    "version": "c4ad6f88c531de58221c73dd91a75af7138334b8",
    "updated_at": "2026-11-10T01:15:02.829Z",
    "headings": [
      {
        "id": "api/commands/eq#eq",
        "text": "eq",
        "level": 1
      },
      {
        "id": "api/commands/eq#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/eq#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/eq#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/eq#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/eq#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/eq#index",
        "text": "Index",
        "level": 3
      },
      {
        "id": "api/commands/eq#get-the-2nd-item-in-a-list-with-eq",
        "text": "Get the 2nd item in a list with .eq()",
        "level": 4
      },
      {
        "id": "api/commands/eq#assert-on-the-3rd-row-of-a-table-with-eq",
        "text": "Assert on the 3rd row of a table with .eq()",
        "level": 4
      },
      {
        "id": "api/commands/eq#index-from-end",
        "text": "Index from end",
        "level": 3
      },
      {
        "id": "api/commands/eq#get-the-2nd-to-last-item-in-a-list-with-eq",
        "text": "Get the 2nd-to-last item in a list with .eq()",
        "level": 4
      },
      {
        "id": "api/commands/eq#common-workflows-with-eq",
        "text": "Common workflows with .eq()",
        "level": 3
      },
      {
        "id": "api/commands/eq#wait-for-the-element-at-an-index-to-render-with-eq",
        "text": "Wait for the element at an index to render with .eq()",
        "level": 4
      },
      {
        "id": "api/commands/eq#move-a-table-row-up-and-check-its-position-with-eq",
        "text": "Move a table row up and check its position with .eq()",
        "level": 4
      },
      {
        "id": "api/commands/eq#click-an-item-after-the-list-finishes-loading-with-eq",
        "text": "Click an item after the list finishes loading with .eq()",
        "level": 4
      },
      {
        "id": "api/commands/eq#check-table-row-order-after-sorting-with-eq",
        "text": "Check table row order after sorting with .eq()",
        "level": 4
      },
      {
        "id": "api/commands/eq#options",
        "text": "Options",
        "level": 3
      },
      {
        "id": "api/commands/eq#wait-longer-for-eq-with-the-timeout-option",
        "text": "Wait longer for .eq() with the timeout option",
        "level": 4
      },
      {
        "id": "api/commands/eq#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/eq#how-eq-compares-to-first-and-last",
        "text": "How .eq() compares to .first() and .last()",
        "level": 3
      },
      {
        "id": "api/commands/eq#what-happens-when-the-eq-index-is-out-of-range",
        "text": "What happens when the .eq() index is out of range",
        "level": 3
      },
      {
        "id": "api/commands/eq#how-eq-compares-to-the-nth-child-selector",
        "text": "How .eq() compares to the :nth-child() selector",
        "level": 3
      },
      {
        "id": "api/commands/eq#how-eq-compares-to-the-jquery-eq-selector",
        "text": "How .eq() compares to the jQuery :eq() selector",
        "level": 3
      },
      {
        "id": "api/commands/eq#when-to-use-select-instead-of-eq-on-options",
        "text": "When to use .select() instead of .eq() on options",
        "level": 3
      },
      {
        "id": "api/commands/eq#how-an-aliased-eq-re-queries-the-current-dom",
        "text": "How an aliased .eq() re-queries the current DOM",
        "level": 3
      },
      {
        "id": "api/commands/eq#when-to-use-eq-instead-of-a-data-cy-selector",
        "text": "When to use .eq() instead of a data-cy selector",
        "level": 3
      },
      {
        "id": "api/commands/eq#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/eq#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/eq#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/eq#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/eq#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/eq#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/eq#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/eq#syntax",
      "doc_id": "api/commands/eq",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.eq(index)\n.eq(indexFromEnd)\n.eq(index, options)\n.eq(indexFromEnd, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('tbody>tr').eq(0) // Yield first 'tr' in 'tbody'\ncy.get('ul>li').eq(4) // Yield fifth 'li' in 'ul'\n```\n\n**Incorrect Usage**\n\n```\ncy.eq(0) // Errors, cannot be chained off 'cy'\ncy.getCookies().eq(4) // Errors, 'getCookies' does not yield DOM element\n```\n\n### Arguments\n\n**index _(Number)_**\n\nThe position of the element to get within the set of elements, counting from `0`.\n\n**indexFromEnd _(Number)_**\n\nA negative number that counts back from the end of the set of elements. `-1` is the last element.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.eq()`.\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 `.eq()` to resolve before [timing out](#Timeouts) |\n\n### Yields\n\n*   `.eq()` yields the DOM element at the given index within the set it was given.\n*   `.eq()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 239
    },
    {
      "id": "api/commands/eq#usage",
      "doc_id": "api/commands/eq",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('tbody>tr').eq(0) // Yield first 'tr' in 'tbody'\ncy.get('ul>li').eq(4) // Yield fifth 'li' in 'ul'\n```\n\n**Incorrect Usage**\n\n```\ncy.eq(0) // Errors, cannot be chained off 'cy'\ncy.getCookies().eq(4) // Errors, 'getCookies' does not yield DOM element\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 55
    },
    {
      "id": "api/commands/eq#arguments",
      "doc_id": "api/commands/eq",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**index _(Number)_**\n\nThe position of the element to get within the set of elements, counting from `0`.\n\n**indexFromEnd _(Number)_**\n\nA negative number that counts back from the end of the set of elements. `-1` is the last element.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.eq()`.\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 `.eq()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 129
    },
    {
      "id": "api/commands/eq#yields",
      "doc_id": "api/commands/eq",
      "heading": "Yields",
      "heading_level": 3,
      "content_markdown": "### Yields\n\n*   `.eq()` yields the DOM element at the given index within the set it was given.\n*   `.eq()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "yields"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 41
    },
    {
      "id": "api/commands/eq#examples",
      "doc_id": "api/commands/eq",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### Index\n\n#### Get the 2nd item in a list with `.eq()`\n\n```\n<ul>\n  <li>tabby</li>\n  <li>siamese</li>\n  <li>persian</li>\n  <li>sphynx</li>\n  <li>burmese</li>\n</ul>\n```\n\n```\ncy.get('li').eq(1).should('contain', 'siamese')\n```\n\n#### Assert on the 3rd row of a table with `.eq()`\n\nThe header row is a `<tr>` too, so it sits at index `0`.\n\n```\n<table>\n  <tr>\n    <th>Breed</th>\n    <th>Origin</th>\n  </tr>\n  <tr>\n    <td>Siamese</td>\n    <td>Thailand</td>\n  </tr>\n  <tr>\n    <td>Sphynx</td>\n    <td>Canada</td>\n  </tr>\n  <tr>\n    <td>Persian</td>\n    <td>Iran</td>\n  </tr>\n</table>\n```\n\n```\ncy.get('tr').eq(2).should('contain', 'Canada')\n```\n\n### Index from end\n\n#### Get the 2nd-to-last item in a list with `.eq()`\n\n```\n<ul>\n  <li>tabby</li>\n  <li>siamese</li>\n  <li>persian</li>\n  <li>sphynx</li>\n  <li>burmese</li>\n</ul>\n```\n\n```\ncy.get('li').eq(-2).should('contain', 'sphynx')\n```\n\n### Common workflows with `.eq()`\n\n#### Wait for the element at an index to render with `.eq()`\n\n`cy.get()` and `.eq()` are both queries, so Cypress re-runs them together until an element exists at the index. Here, the results render one at a time, and `.eq(2)` waits for the third one.\n\nindex.html\n\n```\n<ul class=\"results\"></ul>\n<!-- results render one at a time, 500 ms apart: Ada, Grace, Katherine, Margaret -->\n```\n\nspec.cy.js\n\n```\ncy.get('.results li').eq(2).should('have.text', 'Katherine')\n```\n\n#### Move a table row up and check its position with `.eq()`\n\n`.eq()` yields a single DOM element, so you can keep chaining queries and actions off it. It also narrows the set to one element before [`.within()`](/llm/markdown/api/commands/within.md), which throws an error when its subject contains more than one element. Here, the test checks where each row ends up, so the index is what's under test.\n\nindex.html\n\n```\n<table>\n  <tbody>\n    <tr>\n      <td>Ada</td>\n      <td><button>Move up</button></td>\n    </tr>\n    <tr>\n      <td>Grace</td>\n      <td><button>Move up</button></td>\n    </tr>\n  </tbody>\n</table>\n<!-- clicking Move up swaps its row with the row above it -->\n```\n\nspec.cy.js\n\n```\ncy.get('tbody tr')\n  .eq(1)\n  .within(() => {\n    cy.contains('Move up').click()\n  })\ncy.get('tbody tr').eq(0).should('contain', 'Grace')\ncy.get('tbody tr').eq(1).should('contain', 'Ada')\n```\n\n#### Click an item after the list finishes loading with `.eq()`\n\nAn action such as [`.click()`](/llm/markdown/api/commands/click.md) is not an assertion, so `cy.get('[data-cy=result]').eq(3).click()` acts on the element at index `3` at that moment. If the list renders placeholder rows before the real results, the element it clicks can be a placeholder. Assert on the finished list before calling `.eq()`, and Cypress retries the query until the assertion passes. Here, the results are ranked, so the test clicks the fourth-ranked result.\n\nindex.html\n\n```\n<ul class=\"results\"></ul>\n<!--\n  4 placeholder <li data-cy=\"result\" class=\"placeholder\"> elements render\n  first, then 10 <li data-cy=\"result\"> results replace them. Clicking a\n  result adds the class \"selected\".\n-->\n```\n\nspec.cy.js\n\n```\ncy.get('[data-cy=result]').should('have.length', 10).eq(3).click()\ncy.get('[data-cy=result]').eq(3).should('have.class', 'selected')\n```\n\n#### Check table row order after sorting with `.eq()`\n\n`cy.get()` and `.eq()` are both queries, so Cypress re-runs them together until the chained assertion passes. After the table re-sorts, the assertion checks whichever row is at the index _now_, which is what you want when testing sort order.\n\nindex.html\n\n```\n<table>\n  <thead>\n    <tr>\n      <th>Name</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td>Grace</td>\n    </tr>\n    <tr>\n      <td>Ada</td>\n    </tr>\n  </tbody>\n</table>\n<!-- clicking the Name header sorts the rows alphabetically -->\n```\n\nspec.cy.js\n\n```\ncy.contains('th', 'Name').click()\ncy.get('tbody tr').eq(0).should('contain', 'Ada')\ncy.get('tbody tr').eq(1).should('contain', 'Grace')\n```\n\n### Options\n\n#### Wait longer for `.eq()` with the `timeout` option\n\nThe `timeout` you pass to `.eq()` sets how long Cypress retries the whole query chain, including the `cy.get()` before it. Here, the third notification appears after 6 seconds, which is past the default 4-second [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts).\n\nindex.html\n\n```\n<ul class=\"notifications\">\n  <li>Saved</li>\n  <li>Uploaded</li>\n</ul>\n<!-- a third <li> with the text \"Synced\" is added after 6 seconds -->\n```\n\nspec.cy.js\n\n```\ncy.get('.notifications li')\n  .eq(2, { timeout: 10000 })\n  .should('have.text', 'Synced')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 765
    },
    {
      "id": "api/commands/eq#index",
      "doc_id": "api/commands/eq",
      "heading": "Index",
      "heading_level": 3,
      "content_markdown": "### Index\n\n#### Get the 2nd item in a list with `.eq()`\n\n```\n<ul>\n  <li>tabby</li>\n  <li>siamese</li>\n  <li>persian</li>\n  <li>sphynx</li>\n  <li>burmese</li>\n</ul>\n```\n\n```\ncy.get('li').eq(1).should('contain', 'siamese')\n```\n\n#### Assert on the 3rd row of a table with `.eq()`\n\nThe header row is a `<tr>` too, so it sits at index `0`.\n\n```\n<table>\n  <tr>\n    <th>Breed</th>\n    <th>Origin</th>\n  </tr>\n  <tr>\n    <td>Siamese</td>\n    <td>Thailand</td>\n  </tr>\n  <tr>\n    <td>Sphynx</td>\n    <td>Canada</td>\n  </tr>\n  <tr>\n    <td>Persian</td>\n    <td>Iran</td>\n  </tr>\n</table>\n```\n\n```\ncy.get('tr').eq(2).should('contain', 'Canada')\n```\n",
      "section": "api",
      "anchors": [
        "index"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 97
    },
    {
      "id": "api/commands/eq#assert-on-the-3rd-row-of-a-table-with-eq",
      "doc_id": "api/commands/eq",
      "heading": "Assert on the 3rd row of a table with .eq()",
      "heading_level": 4,
      "content_markdown": "#### Assert on the 3rd row of a table with `.eq()`\n\nThe header row is a `<tr>` too, so it sits at index `0`.\n\n```\n<table>\n  <tr>\n    <th>Breed</th>\n    <th>Origin</th>\n  </tr>\n  <tr>\n    <td>Siamese</td>\n    <td>Thailand</td>\n  </tr>\n  <tr>\n    <td>Sphynx</td>\n    <td>Canada</td>\n  </tr>\n  <tr>\n    <td>Persian</td>\n    <td>Iran</td>\n  </tr>\n</table>\n```\n\n```\ncy.get('tr').eq(2).should('contain', 'Canada')\n```\n",
      "section": "api",
      "anchors": [
        "assert-on-the-3rd-row-of-a-table-with-eq"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 64
    },
    {
      "id": "api/commands/eq#common-workflows-with-eq",
      "doc_id": "api/commands/eq",
      "heading": "Common workflows with .eq()",
      "heading_level": 3,
      "content_markdown": "### Common workflows with `.eq()`\n\n#### Wait for the element at an index to render with `.eq()`\n\n`cy.get()` and `.eq()` are both queries, so Cypress re-runs them together until an element exists at the index. Here, the results render one at a time, and `.eq(2)` waits for the third one.\n\nindex.html\n\n```\n<ul class=\"results\"></ul>\n<!-- results render one at a time, 500 ms apart: Ada, Grace, Katherine, Margaret -->\n```\n\nspec.cy.js\n\n```\ncy.get('.results li').eq(2).should('have.text', 'Katherine')\n```\n\n#### Move a table row up and check its position with `.eq()`\n\n`.eq()` yields a single DOM element, so you can keep chaining queries and actions off it. It also narrows the set to one element before [`.within()`](/llm/markdown/api/commands/within.md), which throws an error when its subject contains more than one element. Here, the test checks where each row ends up, so the index is what's under test.\n\nindex.html\n\n```\n<table>\n  <tbody>\n    <tr>\n      <td>Ada</td>\n      <td><button>Move up</button></td>\n    </tr>\n    <tr>\n      <td>Grace</td>\n      <td><button>Move up</button></td>\n    </tr>\n  </tbody>\n</table>\n<!-- clicking Move up swaps its row with the row above it -->\n```\n\nspec.cy.js\n\n```\ncy.get('tbody tr')\n  .eq(1)\n  .within(() => {\n    cy.contains('Move up').click()\n  })\ncy.get('tbody tr').eq(0).should('contain', 'Grace')\ncy.get('tbody tr').eq(1).should('contain', 'Ada')\n```\n\n#### Click an item after the list finishes loading with `.eq()`\n\nAn action such as [`.click()`](/llm/markdown/api/commands/click.md) is not an assertion, so `cy.get('[data-cy=result]').eq(3).click()` acts on the element at index `3` at that moment. If the list renders placeholder rows before the real results, the element it clicks can be a placeholder. Assert on the finished list before calling `.eq()`, and Cypress retries the query until the assertion passes. Here, the results are ranked, so the test clicks the fourth-ranked result.\n\nindex.html\n\n```\n<ul class=\"results\"></ul>\n<!--\n  4 placeholder <li data-cy=\"result\" class=\"placeholder\"> elements render\n  first, then 10 <li data-cy=\"result\"> results replace them. Clicking a\n  result adds the class \"selected\".\n-->\n```\n\nspec.cy.js\n\n```\ncy.get('[data-cy=result]').should('have.length', 10).eq(3).click()\ncy.get('[data-cy=result]').eq(3).should('have.class', 'selected')\n```\n\n#### Check table row order after sorting with `.eq()`\n\n`cy.get()` and `.eq()` are both queries, so Cypress re-runs them together until the chained assertion passes. After the table re-sorts, the assertion checks whichever row is at the index _now_, which is what you want when testing sort order.\n\nindex.html\n\n```\n<table>\n  <thead>\n    <tr>\n      <th>Name</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td>Grace</td>\n    </tr>\n    <tr>\n      <td>Ada</td>\n    </tr>\n  </tbody>\n</table>\n<!-- clicking the Name header sorts the rows alphabetically -->\n```\n\nspec.cy.js\n\n```\ncy.contains('th', 'Name').click()\ncy.get('tbody tr').eq(0).should('contain', 'Ada')\ncy.get('tbody tr').eq(1).should('contain', 'Grace')\n```\n",
      "section": "api",
      "anchors": [
        "common-workflows-with-eq"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 523
    },
    {
      "id": "api/commands/eq#wait-for-the-element-at-an-index-to-render-with-eq",
      "doc_id": "api/commands/eq",
      "heading": "Wait for the element at an index to render with .eq()",
      "heading_level": 4,
      "content_markdown": "#### Wait for the element at an index to render with `.eq()`\n\n`cy.get()` and `.eq()` are both queries, so Cypress re-runs them together until an element exists at the index. Here, the results render one at a time, and `.eq(2)` waits for the third one.\n\nindex.html\n\n```\n<ul class=\"results\"></ul>\n<!-- results render one at a time, 500 ms apart: Ada, Grace, Katherine, Margaret -->\n```\n\nspec.cy.js\n\n```\ncy.get('.results li').eq(2).should('have.text', 'Katherine')\n```\n",
      "section": "api",
      "anchors": [
        "wait-for-the-element-at-an-index-to-render-with-eq"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 95
    },
    {
      "id": "api/commands/eq#move-a-table-row-up-and-check-its-position-with-eq",
      "doc_id": "api/commands/eq",
      "heading": "Move a table row up and check its position with .eq()",
      "heading_level": 4,
      "content_markdown": "#### Move a table row up and check its position with `.eq()`\n\n`.eq()` yields a single DOM element, so you can keep chaining queries and actions off it. It also narrows the set to one element before [`.within()`](/llm/markdown/api/commands/within.md), which throws an error when its subject contains more than one element. Here, the test checks where each row ends up, so the index is what's under test.\n\nindex.html\n\n```\n<table>\n  <tbody>\n    <tr>\n      <td>Ada</td>\n      <td><button>Move up</button></td>\n    </tr>\n    <tr>\n      <td>Grace</td>\n      <td><button>Move up</button></td>\n    </tr>\n  </tbody>\n</table>\n<!-- clicking Move up swaps its row with the row above it -->\n```\n\nspec.cy.js\n\n```\ncy.get('tbody tr')\n  .eq(1)\n  .within(() => {\n    cy.contains('Move up').click()\n  })\ncy.get('tbody tr').eq(0).should('contain', 'Grace')\ncy.get('tbody tr').eq(1).should('contain', 'Ada')\n```\n",
      "section": "api",
      "anchors": [
        "move-a-table-row-up-and-check-its-position-with-eq"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 152
    },
    {
      "id": "api/commands/eq#click-an-item-after-the-list-finishes-loading-with-eq",
      "doc_id": "api/commands/eq",
      "heading": "Click an item after the list finishes loading with .eq()",
      "heading_level": 4,
      "content_markdown": "#### Click an item after the list finishes loading with `.eq()`\n\nAn action such as [`.click()`](/llm/markdown/api/commands/click.md) is not an assertion, so `cy.get('[data-cy=result]').eq(3).click()` acts on the element at index `3` at that moment. If the list renders placeholder rows before the real results, the element it clicks can be a placeholder. Assert on the finished list before calling `.eq()`, and Cypress retries the query until the assertion passes. Here, the results are ranked, so the test clicks the fourth-ranked result.\n\nindex.html\n\n```\n<ul class=\"results\"></ul>\n<!--\n  4 placeholder <li data-cy=\"result\" class=\"placeholder\"> elements render\n  first, then 10 <li data-cy=\"result\"> results replace them. Clicking a\n  result adds the class \"selected\".\n-->\n```\n\nspec.cy.js\n\n```\ncy.get('[data-cy=result]').should('have.length', 10).eq(3).click()\ncy.get('[data-cy=result]').eq(3).should('have.class', 'selected')\n```\n",
      "section": "api",
      "anchors": [
        "click-an-item-after-the-list-finishes-loading-with-eq"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 153
    },
    {
      "id": "api/commands/eq#check-table-row-order-after-sorting-with-eq",
      "doc_id": "api/commands/eq",
      "heading": "Check table row order after sorting with .eq()",
      "heading_level": 4,
      "content_markdown": "#### Check table row order after sorting with `.eq()`\n\n`cy.get()` and `.eq()` are both queries, so Cypress re-runs them together until the chained assertion passes. After the table re-sorts, the assertion checks whichever row is at the index _now_, which is what you want when testing sort order.\n\nindex.html\n\n```\n<table>\n  <thead>\n    <tr>\n      <th>Name</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td>Grace</td>\n    </tr>\n    <tr>\n      <td>Ada</td>\n    </tr>\n  </tbody>\n</table>\n<!-- clicking the Name header sorts the rows alphabetically -->\n```\n\nspec.cy.js\n\n```\ncy.contains('th', 'Name').click()\ncy.get('tbody tr').eq(0).should('contain', 'Ada')\ncy.get('tbody tr').eq(1).should('contain', 'Grace')\n```\n",
      "section": "api",
      "anchors": [
        "check-table-row-order-after-sorting-with-eq"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 116
    },
    {
      "id": "api/commands/eq#options",
      "doc_id": "api/commands/eq",
      "heading": "Options",
      "heading_level": 3,
      "content_markdown": "### Options\n\n#### Wait longer for `.eq()` with the `timeout` option\n\nThe `timeout` you pass to `.eq()` sets how long Cypress retries the whole query chain, including the `cy.get()` before it. Here, the third notification appears after 6 seconds, which is past the default 4-second [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts).\n\nindex.html\n\n```\n<ul class=\"notifications\">\n  <li>Saved</li>\n  <li>Uploaded</li>\n</ul>\n<!-- a third <li> with the text \"Synced\" is added after 6 seconds -->\n```\n\nspec.cy.js\n\n```\ncy.get('.notifications li')\n  .eq(2, { timeout: 10000 })\n  .should('have.text', 'Synced')\n```\n",
      "section": "api",
      "anchors": [
        "options"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 107
    },
    {
      "id": "api/commands/eq#wait-longer-for-eq-with-the-timeout-option",
      "doc_id": "api/commands/eq",
      "heading": "Wait longer for .eq() with the timeout option",
      "heading_level": 4,
      "content_markdown": "#### Wait longer for `.eq()` with the `timeout` option\n\nThe `timeout` you pass to `.eq()` sets how long Cypress retries the whole query chain, including the `cy.get()` before it. Here, the third notification appears after 6 seconds, which is past the default 4-second [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts).\n\nindex.html\n\n```\n<ul class=\"notifications\">\n  <li>Saved</li>\n  <li>Uploaded</li>\n</ul>\n<!-- a third <li> with the text \"Synced\" is added after 6 seconds -->\n```\n\nspec.cy.js\n\n```\ncy.get('.notifications li')\n  .eq(2, { timeout: 10000 })\n  .should('have.text', 'Synced')\n```\n",
      "section": "api",
      "anchors": [
        "wait-longer-for-eq-with-the-timeout-option"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 104
    },
    {
      "id": "api/commands/eq#notes",
      "doc_id": "api/commands/eq",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### How `.eq()` compares to `.first()` and `.last()`\n\n`.eq(0)` yields the same element as [`.first()`](/llm/markdown/api/commands/first.md), and `.eq(-1)` yields the same element as [`.last()`](/llm/markdown/api/commands/last.md).\n\n### What happens when the `.eq()` index is out of range\n\nWhen no element exists at the index, `.eq()` yields an empty set. Cypress retries until an element appears at the index. If none appears before the [timeout](#Wait-longer-for-eq-with-the-timeout-option), it fails with an error such as ``Expected to find element: `5`, but never found it.`` To assert that the set has no element at an index, chain `.should('not.exist')`.\n\n```\n<ul>\n  <li>tabby</li>\n  <li>siamese</li>\n  <li>persian</li>\n  <li>sphynx</li>\n  <li>burmese</li>\n</ul>\n```\n\n```\ncy.get('li').eq(5).should('not.exist')\n```\n\n### How `.eq()` compares to the `:nth-child()` selector\n\n`.eq()` counts across the whole set and yields a single element. The CSS `:nth-child()` selector counts from `1` within _each_ parent, so it can match several elements when the set spans more than one parent.\n\n```\n<ul class=\"fruits\">\n  <li>Apple</li>\n  <li>Banana</li>\n</ul>\n<ul class=\"veggies\">\n  <li>Carrot</li>\n  <li>Daikon</li>\n</ul>\n```\n\n```\ncy.get('li').eq(1) // yields <li>Banana</li>\ncy.get('li:nth-child(2)') // yields <li>Banana</li> and <li>Daikon</li>\n```\n\n### How `.eq()` compares to the jQuery `:eq()` selector\n\n`cy.get()` accepts jQuery selectors, so `cy.get('li:eq(1)')` yields the same element as `cy.get('li').eq(1)`. jQuery deprecated the [`:eq()` selector](https://api.jquery.com/eq-selector/) in jQuery 3.4 and removed it in jQuery 4, so use the `.eq()` command instead.\n\n```\ncy.get('li:eq(1)') // deprecated jQuery selector\ncy.get('li').eq(1) // use the .eq() command instead\n```\n\n### When to use `.select()` instead of `.eq()` on options\n\n`.eq()` yields an `<option>` element without selecting it, so the `<select>` keeps its value. Calling `.click()` on the option doesn't select it either: Cypress fails because the option isn't visible. To choose an option by its position, pass the index to [`.select()`](/llm/markdown/api/commands/select.md).\n\n```\n<select>\n  <option value=\"small\">Small</option>\n  <option value=\"medium\">Medium</option>\n  <option value=\"large\">Large</option>\n</select>\n```\n\n```\ncy.get('select').select(1).should('have.value', 'medium')\n```\n\n### How an aliased `.eq()` re-queries the current DOM\n\nAn alias stores the query chain, not the element it found. Each time you use the alias, Cypress re-runs the chain against the current DOM, so an aliased `.eq()` yields whichever element is at that index _now_. Learn more in [aliasing DOM elements](/llm/markdown/app/core-concepts/variables-and-aliases.md#Elements).\n\nindex.html\n\n```\n<input class=\"new-todo\" />\n<ul class=\"todo-list\">\n  <li>Buy milk</li>\n  <li>Walk dog</li>\n</ul>\n<!-- pressing Enter in .new-todo adds the text as a new <li> at the top of the list -->\n```\n\nspec.cy.js\n\n```\ncy.get('.todo-list li').eq(1).as('second')\ncy.get('@second').should('have.text', 'Walk dog')\n\ncy.get('.new-todo').type('Write docs{enter}')\ncy.get('@second').should('have.text', 'Buy milk')\n```\n\n### When to use `.eq()` instead of a `data-cy` selector\n\nAn index is tied to the order of the elements on the page. When that order changes, such as a new item added at the top of a list, `.eq()` selects a different element and the test breaks for a reason unrelated to what it checks. Use `.eq()` when the position itself is what you're testing, such as sort order or the newest item in a feed. Otherwise, select the element by a `data-cy` attribute. Learn more in [selecting elements](/llm/markdown/app/core-concepts/best-practices.md#Selecting-Elements).\n\n```\n// position matters: the first row after sorting\ncy.get('tbody tr').eq(0).should('contain', 'Ada')\n\n// position doesn't matter: the row for a specific user\ncy.get('[data-cy=user-ada]').should('be.visible')\n```\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 671
    },
    {
      "id": "api/commands/eq#what-happens-when-the-eq-index-is-out-of-range",
      "doc_id": "api/commands/eq",
      "heading": "What happens when the .eq() index is out of range",
      "heading_level": 3,
      "content_markdown": "### What happens when the `.eq()` index is out of range\n\nWhen no element exists at the index, `.eq()` yields an empty set. Cypress retries until an element appears at the index. If none appears before the [timeout](#Wait-longer-for-eq-with-the-timeout-option), it fails with an error such as ``Expected to find element: `5`, but never found it.`` To assert that the set has no element at an index, chain `.should('not.exist')`.\n\n```\n<ul>\n  <li>tabby</li>\n  <li>siamese</li>\n  <li>persian</li>\n  <li>sphynx</li>\n  <li>burmese</li>\n</ul>\n```\n\n```\ncy.get('li').eq(5).should('not.exist')\n```\n",
      "section": "api",
      "anchors": [
        "what-happens-when-the-eq-index-is-out-of-range"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 105
    },
    {
      "id": "api/commands/eq#how-eq-compares-to-the-nth-child-selector",
      "doc_id": "api/commands/eq",
      "heading": "How .eq() compares to the :nth-child() selector",
      "heading_level": 3,
      "content_markdown": "### How `.eq()` compares to the `:nth-child()` selector\n\n`.eq()` counts across the whole set and yields a single element. The CSS `:nth-child()` selector counts from `1` within _each_ parent, so it can match several elements when the set spans more than one parent.\n\n```\n<ul class=\"fruits\">\n  <li>Apple</li>\n  <li>Banana</li>\n</ul>\n<ul class=\"veggies\">\n  <li>Carrot</li>\n  <li>Daikon</li>\n</ul>\n```\n\n```\ncy.get('li').eq(1) // yields <li>Banana</li>\ncy.get('li:nth-child(2)') // yields <li>Banana</li> and <li>Daikon</li>\n```\n",
      "section": "api",
      "anchors": [
        "how-eq-compares-to-the-nth-child-selector"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 89
    },
    {
      "id": "api/commands/eq#how-eq-compares-to-the-jquery-eq-selector",
      "doc_id": "api/commands/eq",
      "heading": "How .eq() compares to the jQuery :eq() selector",
      "heading_level": 3,
      "content_markdown": "### How `.eq()` compares to the jQuery `:eq()` selector\n\n`cy.get()` accepts jQuery selectors, so `cy.get('li:eq(1)')` yields the same element as `cy.get('li').eq(1)`. jQuery deprecated the [`:eq()` selector](https://api.jquery.com/eq-selector/) in jQuery 3.4 and removed it in jQuery 4, so use the `.eq()` command instead.\n\n```\ncy.get('li:eq(1)') // deprecated jQuery selector\ncy.get('li').eq(1) // use the .eq() command instead\n```\n",
      "section": "api",
      "anchors": [
        "how-eq-compares-to-the-jquery-eq-selector"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 73
    },
    {
      "id": "api/commands/eq#when-to-use-select-instead-of-eq-on-options",
      "doc_id": "api/commands/eq",
      "heading": "When to use .select() instead of .eq() on options",
      "heading_level": 3,
      "content_markdown": "### When to use `.select()` instead of `.eq()` on options\n\n`.eq()` yields an `<option>` element without selecting it, so the `<select>` keeps its value. Calling `.click()` on the option doesn't select it either: Cypress fails because the option isn't visible. To choose an option by its position, pass the index to [`.select()`](/llm/markdown/api/commands/select.md).\n\n```\n<select>\n  <option value=\"small\">Small</option>\n  <option value=\"medium\">Medium</option>\n  <option value=\"large\">Large</option>\n</select>\n```\n\n```\ncy.get('select').select(1).should('have.value', 'medium')\n```\n",
      "section": "api",
      "anchors": [
        "when-to-use-select-instead-of-eq-on-options"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 88
    },
    {
      "id": "api/commands/eq#how-an-aliased-eq-re-queries-the-current-dom",
      "doc_id": "api/commands/eq",
      "heading": "How an aliased .eq() re-queries the current DOM",
      "heading_level": 3,
      "content_markdown": "### How an aliased `.eq()` re-queries the current DOM\n\nAn alias stores the query chain, not the element it found. Each time you use the alias, Cypress re-runs the chain against the current DOM, so an aliased `.eq()` yields whichever element is at that index _now_. Learn more in [aliasing DOM elements](/llm/markdown/app/core-concepts/variables-and-aliases.md#Elements).\n\nindex.html\n\n```\n<input class=\"new-todo\" />\n<ul class=\"todo-list\">\n  <li>Buy milk</li>\n  <li>Walk dog</li>\n</ul>\n<!-- pressing Enter in .new-todo adds the text as a new <li> at the top of the list -->\n```\n\nspec.cy.js\n\n```\ncy.get('.todo-list li').eq(1).as('second')\ncy.get('@second').should('have.text', 'Walk dog')\n\ncy.get('.new-todo').type('Write docs{enter}')\ncy.get('@second').should('have.text', 'Buy milk')\n```\n",
      "section": "api",
      "anchors": [
        "how-an-aliased-eq-re-queries-the-current-dom"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 129
    },
    {
      "id": "api/commands/eq#when-to-use-eq-instead-of-a-data-cy-selector",
      "doc_id": "api/commands/eq",
      "heading": "When to use .eq() instead of a data-cy selector",
      "heading_level": 3,
      "content_markdown": "### When to use `.eq()` instead of a `data-cy` selector\n\nAn index is tied to the order of the elements on the page. When that order changes, such as a new item added at the top of a list, `.eq()` selects a different element and the test breaks for a reason unrelated to what it checks. Use `.eq()` when the position itself is what you're testing, such as sort order or the newest item in a feed. Otherwise, select the element by a `data-cy` attribute. Learn more in [selecting elements](/llm/markdown/app/core-concepts/best-practices.md#Selecting-Elements).\n\n```\n// position matters: the first row after sorting\ncy.get('tbody tr').eq(0).should('contain', 'Ada')\n\n// position doesn't matter: the row for a specific user\ncy.get('[data-cy=user-ada]').should('be.visible')\n```\n",
      "section": "api",
      "anchors": [
        "when-to-use-eq-instead-of-a-data-cy-selector"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 152
    },
    {
      "id": "api/commands/eq#rules",
      "doc_id": "api/commands/eq",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `.eq()` requires being chained off a command that yields DOM element(s) or a document.\n\n### Assertions\n\n*   `.eq()` 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*   `.eq()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.\n\n### Timeouts\n\n*   `.eq()` 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*   `.eq()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 96
    },
    {
      "id": "api/commands/eq#command-log",
      "doc_id": "api/commands/eq",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Find the 4th `<li>` in the list_**\n\n```\ncy.get('ul').find('li').eq(3)\n```\n\nThe commands above display in the Command Log as:\n\nClick the `eq` command in the Command Log to print the following to the console:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 49
    },
    {
      "id": "api/commands/eq#history",
      "doc_id": "api/commands/eq",
      "heading": "History",
      "heading_level": 2,
      "content_markdown": "## History\n\n| Version | Changes |\n| --- | --- |\n| [12.6.0](/llm/markdown/app/references/changelog.md#12-6-0) | Overwrite `.eq()` with [`Cypress.Commands.overwriteQuery()`](/llm/markdown/api/cypress-api/custom-queries.md#Overwriting-Existing-Queries) rather than `Cypress.Commands.overwrite()`. |\n| [12.0.0](/llm/markdown/app/references/changelog.md#12-0-0) | `.eq()` is now a query. |\n",
      "section": "api",
      "anchors": [
        "history"
      ],
      "path": "/llm/json/chunked/api/commands/eq.json",
      "token_estimate": 43
    }
  ]
}