{
  "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
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "eq"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Get a DOM element at a specific index within a set of DOM elements."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The querying behavior of this command matches exactly how "
          },
          {
            "type": "link",
            "title": null,
            "url": "https://api.jquery.com/eq",
            "children": [
              {
                "type": "text",
                "value": "`.eq()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " works in jQuery."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": ".eq(index)\n.eq(indexFromEnd)\n.eq(index, options)\n.eq(indexFromEnd, options)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('tbody>tr').eq(0) // Yield first 'tr' in 'tbody'\ncy.get('ul>li').eq(4) // Yield fifth 'li' in 'ul'"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Incorrect Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.eq(0) // Errors, cannot be chained off 'cy'\ncy.getCookies().eq(4) // Errors, 'getCookies' does not yield DOM element"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "index (Number)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The position of the element to get within the set of elements, counting from `0`."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "indexFromEnd (Number)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "A negative number that counts back from the end of the set of elements. `-1` is the last element."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "options (Object)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Pass in an options object to change the default behavior of `.eq()`."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Default"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`log`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Displays the command in the "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/open-mode.md#Command-Log",
                    "children": [
                      {
                        "type": "text",
                        "value": "Command log"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`timeout`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "`defaultCommandTimeout`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Time to wait for `.eq()` to resolve before "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "timing out"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Yields"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.eq()` yields the DOM element at the given index within the set it was given."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.eq()` is a query, and it is safe to chain further commands."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Index"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Get the 2nd item in a list with `.eq()`"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<ul>\n  <li>tabby</li>\n  <li>siamese</li>\n  <li>persian</li>\n  <li>sphynx</li>\n  <li>burmese</li>\n</ul>"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('li').eq(1).should('contain', 'siamese')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Assert on the 3rd row of a table with `.eq()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The header row is a `<tr>` too, so it sits at index `0`."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<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>"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('tr').eq(2).should('contain', 'Canada')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Index from end"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Get the 2nd-to-last item in a list with `.eq()`"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<ul>\n  <li>tabby</li>\n  <li>siamese</li>\n  <li>persian</li>\n  <li>sphynx</li>\n  <li>burmese</li>\n</ul>"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('li').eq(-2).should('contain', 'sphynx')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Common workflows with `.eq()`"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Wait for the element at an index to render with `.eq()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`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."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "index.html"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<ul class=\"results\"></ul>\n<!-- results render one at a time, 500 ms apart: Ada, Grace, Katherine, Margaret -->"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "spec.cy.js"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('.results li').eq(2).should('have.text', 'Katherine')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Move a table row up and check its position with `.eq()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`.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 "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/within.md",
            "children": [
              {
                "type": "text",
                "value": "`.within()`"
              }
            ]
          },
          {
            "type": "text",
            "value": ", 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."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "index.html"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<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 -->"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "spec.cy.js"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.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')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Click an item after the list finishes loading with `.eq()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "An action such as "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/click.md",
            "children": [
              {
                "type": "text",
                "value": "`.click()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " 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."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "index.html"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<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-->"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "spec.cy.js"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('[data-cy=result]').should('have.length', 10).eq(3).click()\ncy.get('[data-cy=result]').eq(3).should('have.class', 'selected')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Check table row order after sorting with `.eq()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`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."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "index.html"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<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 -->"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "spec.cy.js"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.contains('th', 'Name').click()\ncy.get('tbody tr').eq(0).should('contain', 'Ada')\ncy.get('tbody tr').eq(1).should('contain', 'Grace')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Options"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Wait longer for `.eq()` with the `timeout` option"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The `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 "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/configuration.md#Timeouts",
            "children": [
              {
                "type": "text",
                "value": "`defaultCommandTimeout`"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "index.html"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<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 -->"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "spec.cy.js"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('.notifications li')\n  .eq(2, { timeout: 10000 })\n  .should('have.text', 'Synced')"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Notes"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "How `.eq()` compares to `.first()` and `.last()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`.eq(0)` yields the same element as "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/first.md",
            "children": [
              {
                "type": "text",
                "value": "`.first()`"
              }
            ]
          },
          {
            "type": "text",
            "value": ", and `.eq(-1)` yields the same element as "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/last.md",
            "children": [
              {
                "type": "text",
                "value": "`.last()`"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "What happens when the `.eq()` index is out of range"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When 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 "
          },
          {
            "type": "link",
            "title": null,
            "url": "#Wait-longer-for-eq-with-the-timeout-option",
            "children": [
              {
                "type": "text",
                "value": "timeout"
              }
            ]
          },
          {
            "type": "text",
            "value": ", 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')`."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<ul>\n  <li>tabby</li>\n  <li>siamese</li>\n  <li>persian</li>\n  <li>sphynx</li>\n  <li>burmese</li>\n</ul>"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('li').eq(5).should('not.exist')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "How `.eq()` compares to the `:nth-child()` selector"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`.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."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<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>"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('li').eq(1) // yields <li>Banana</li>\ncy.get('li:nth-child(2)') // yields <li>Banana</li> and <li>Daikon</li>"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "How `.eq()` compares to the jQuery `:eq()` selector"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.get()` accepts jQuery selectors, so `cy.get('li:eq(1)')` yields the same element as `cy.get('li').eq(1)`. jQuery deprecated the "
          },
          {
            "type": "link",
            "title": null,
            "url": "https://api.jquery.com/eq-selector/",
            "children": [
              {
                "type": "text",
                "value": "`:eq()` selector"
              }
            ]
          },
          {
            "type": "text",
            "value": " in jQuery 3.4 and removed it in jQuery 4, so use the `.eq()` command instead."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('li:eq(1)') // deprecated jQuery selector\ncy.get('li').eq(1) // use the .eq() command instead"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "When to use `.select()` instead of `.eq()` on options"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`.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 "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/select.md",
            "children": [
              {
                "type": "text",
                "value": "`.select()`"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<select>\n  <option value=\"small\">Small</option>\n  <option value=\"medium\">Medium</option>\n  <option value=\"large\">Large</option>\n</select>"
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('select').select(1).should('have.value', 'medium')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "How an aliased `.eq()` re-queries the current DOM"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "An 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 "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/variables-and-aliases.md#Elements",
            "children": [
              {
                "type": "text",
                "value": "aliasing DOM elements"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "index.html"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<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 -->"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "spec.cy.js"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.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')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "When to use `.eq()` instead of a `data-cy` selector"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "An 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 "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/core-concepts/best-practices.md#Selecting-Elements",
            "children": [
              {
                "type": "text",
                "value": "selecting elements"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "// 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')"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Rules"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Requirements"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.eq()` requires being chained off a command that yields DOM element(s) or a document."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Assertions"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.eq()` will automatically "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "retry"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " until the element(s) "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Implicit-Assertions",
                    "children": [
                      {
                        "type": "text",
                        "value": "exist in the DOM"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.eq()` will automatically "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "retry"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " until all chained assertions have passed."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Timeouts"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.eq()` can time out waiting for the element(s) to "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/introduction-to-cypress.md#Implicit-Assertions",
                    "children": [
                      {
                        "type": "text",
                        "value": "exist in the DOM"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": "."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`.eq()` can time out waiting for assertions you've added to pass."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Command Log"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Find the 4th `<li>` in the list"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('ul').find('li').eq(3)"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The commands above display in the Command Log as:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Click the `eq` command in the Command Log to print the following to the console:"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "History"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Version"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Changes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#12-6-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "12.6.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Overwrite `.eq()` with "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/cypress-api/custom-queries.md#Overwriting-Existing-Queries",
                    "children": [
                      {
                        "type": "text",
                        "value": "`Cypress.Commands.overwriteQuery()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " rather than `Cypress.Commands.overwrite()`."
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#12-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "12.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`.eq()` is now a query."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/filter.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.filter()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/first.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.first()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/last.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.last()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/next.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.next()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/prev.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`.prev()`"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 1919
}