{
  "doc": {
    "id": "api/commands/next",
    "title": "cy.next()",
    "description": "Get the immediately following sibling of each DOM element within a set of DOM elements in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/next.md",
    "version": "f97f06d85653c51afe39a9bd3cefda946807f150",
    "updated_at": "2026-10-05T21:01:45.863Z",
    "headings": [
      {
        "id": "api/commands/next#next",
        "text": "next",
        "level": 1
      },
      {
        "id": "api/commands/next#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/next#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/next#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/next#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/next#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/next#no-args",
        "text": "No Args",
        "level": 3
      },
      {
        "id": "api/commands/next#find-the-element-next-to-second",
        "text": "Find the element next to .second",
        "level": 4
      },
      {
        "id": "api/commands/next#testing-a-datalist",
        "text": "Testing a datalist",
        "level": 4
      },
      {
        "id": "api/commands/next#selector",
        "text": "Selector",
        "level": 3
      },
      {
        "id": "api/commands/next#find-the-very-next-sibling-of-each-li-keep-only-the-ones-with-a-class-selected",
        "text": "Find the very next sibling of each li. Keep only the ones with a class selected",
        "level": 4
      },
      {
        "id": "api/commands/next#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/next#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/next#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/next#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/next#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/next#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/next#syntax",
      "doc_id": "api/commands/next",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.next()\n.next(selector)\n.next(options)\n.next(selector, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('nav a:first').next() // Yield next link in nav\n```\n\n**Incorrect Usage**\n\n```\ncy.next() // Errors, cannot be chained off 'cy'\ncy.getCookies().next() // Errors, 'getCookies' does not yield DOM element\n```\n\n### Arguments\n\n**selector _(String selector)_**\n\nA selector used to filter matching DOM elements.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.next()`.\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 `.next()` to resolve before [timing out](#Timeouts) |\n\n### Yields\n\n*   `.next()` yields the new DOM element(s) it found.\n*   `.next()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 184
    },
    {
      "id": "api/commands/next#usage",
      "doc_id": "api/commands/next",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('nav a:first').next() // Yield next link in nav\n```\n\n**Incorrect Usage**\n\n```\ncy.next() // Errors, cannot be chained off 'cy'\ncy.getCookies().next() // Errors, 'getCookies' does not yield DOM element\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 47
    },
    {
      "id": "api/commands/next#arguments",
      "doc_id": "api/commands/next",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**selector _(String selector)_**\n\nA selector used to filter matching DOM elements.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.next()`.\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 `.next()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 93
    },
    {
      "id": "api/commands/next#examples",
      "doc_id": "api/commands/next",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### No Args\n\n#### Find the element next to `.second`\n\n```\n<ul>\n  <li>apples</li>\n  <li class=\"second\">oranges</li>\n  <li>bananas</li>\n</ul>\n```\n\n```\n// yields <li>bananas</li>\ncy.get('.second').next()\n```\n\n#### Testing a datalist\n\n```\n<input list=\"fruit\" />\n<datalist id=\"fruit\">\n  <option>Apple</option>\n  <option>Banana</option>\n  <option>Cantaloupe</option>\n</datalist>\n```\n\n```\ncy.get('#fruit option')\n  .first()\n  .should('have.text', 'Apple')\n  .next()\n  .should('have.text', 'Banana')\n  .next()\n  .should('have.text', 'Cantaloupe')\n```\n\n### Selector\n\n#### Find the very next sibling of each li. Keep only the ones with a class `selected`\n\n```\n<ul>\n  <li>apples</li>\n  <li>oranges</li>\n  <li>bananas</li>\n  <li class=\"selected\">pineapples</li>\n</ul>\n```\n\n```\n// yields <li>pineapples</li>\ncy.get('li').next('.selected')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 117
    },
    {
      "id": "api/commands/next#no-args",
      "doc_id": "api/commands/next",
      "heading": "No Args",
      "heading_level": 3,
      "content_markdown": "### No Args\n\n#### Find the element next to `.second`\n\n```\n<ul>\n  <li>apples</li>\n  <li class=\"second\">oranges</li>\n  <li>bananas</li>\n</ul>\n```\n\n```\n// yields <li>bananas</li>\ncy.get('.second').next()\n```\n\n#### Testing a datalist\n\n```\n<input list=\"fruit\" />\n<datalist id=\"fruit\">\n  <option>Apple</option>\n  <option>Banana</option>\n  <option>Cantaloupe</option>\n</datalist>\n```\n\n```\ncy.get('#fruit option')\n  .first()\n  .should('have.text', 'Apple')\n  .next()\n  .should('have.text', 'Banana')\n  .next()\n  .should('have.text', 'Cantaloupe')\n```\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 69
    },
    {
      "id": "api/commands/next#selector",
      "doc_id": "api/commands/next",
      "heading": "Selector",
      "heading_level": 3,
      "content_markdown": "### Selector\n\n#### Find the very next sibling of each li. Keep only the ones with a class `selected`\n\n```\n<ul>\n  <li>apples</li>\n  <li>oranges</li>\n  <li>bananas</li>\n  <li class=\"selected\">pineapples</li>\n</ul>\n```\n\n```\n// yields <li>pineapples</li>\ncy.get('li').next('.selected')\n```\n",
      "section": "api",
      "anchors": [
        "selector"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 45
    },
    {
      "id": "api/commands/next#find-the-very-next-sibling-of-each-li-keep-only-the-ones-with-a-class-selected",
      "doc_id": "api/commands/next",
      "heading": "Find the very next sibling of each li. Keep only the ones with a class selected",
      "heading_level": 4,
      "content_markdown": "#### Find the very next sibling of each li. Keep only the ones with a class `selected`\n\n```\n<ul>\n  <li>apples</li>\n  <li>oranges</li>\n  <li>bananas</li>\n  <li class=\"selected\">pineapples</li>\n</ul>\n```\n\n```\n// yields <li>pineapples</li>\ncy.get('li').next('.selected')\n```\n",
      "section": "api",
      "anchors": [
        "find-the-very-next-sibling-of-each-li-keep-only-the-ones-with-a-class-selected"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 43
    },
    {
      "id": "api/commands/next#rules",
      "doc_id": "api/commands/next",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `.next()` requires being chained off a command that yields DOM element(s) or a document.\n\n### Assertions\n\n*   `.next()` 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*   `.next()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed.\n\n### Timeouts\n\n*   `.next()` 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*   `.next()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 96
    },
    {
      "id": "api/commands/next#command-log",
      "doc_id": "api/commands/next",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Find the element next to the `.active` li_**\n\n```\ncy.get('.left-nav').find('li.active').next()\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on `next` within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 49
    }
  ]
}