{
  "doc": {
    "id": "api/commands/next",
    "title": "next | Cypress Documentation",
    "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": "a8fd16711bdda4c7b5645b9717e588ae99ec2470",
    "updated_at": "2026-05-18T17:21:32.047Z",
    "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-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "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-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/next#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/next#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about 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().next(selector).next(options).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'cy.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 [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\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'cy.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": 45
    },
    {
      "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>  <li>apples</li>  <li class=\"second\">oranges</li>  <li>bananas</li></ul>\n```\n\n```\n// yields <li>bananas</li>cy.get('.second').next()\n```\n\n#### Testing a datalist\n\n```\n<input list=\"fruit\" /><datalist id=\"fruit\">  <option>Apple</option>  <option>Banana</option>  <option>Cantaloupe</option></datalist>\n```\n\n```\ncy.get('#fruit option')  .first()  .should('have.text', 'Apple')  .next()  .should('have.text', 'Banana')  .next()  .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>  <li>apples</li>  <li>oranges</li>  <li>bananas</li>  <li class=\"selected\">pineapples</li></ul>\n```\n\n```\n// yields <li>pineapples</li>cy.get('li').next('.selected')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 109
    },
    {
      "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>  <li>apples</li>  <li class=\"second\">oranges</li>  <li>bananas</li></ul>\n```\n\n```\n// yields <li>bananas</li>cy.get('.second').next()\n```\n\n#### Testing a datalist\n\n```\n<input list=\"fruit\" /><datalist id=\"fruit\">  <option>Apple</option>  <option>Banana</option>  <option>Cantaloupe</option></datalist>\n```\n\n```\ncy.get('#fruit option')  .first()  .should('have.text', 'Apple')  .next()  .should('have.text', 'Banana')  .next()  .should('have.text', 'Cantaloupe')\n```\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 64
    },
    {
      "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>  <li>apples</li>  <li>oranges</li>  <li>bananas</li>  <li class=\"selected\">pineapples</li></ul>\n```\n\n```\n// yields <li>pineapples</li>cy.get('li').next('.selected')\n```\n",
      "section": "api",
      "anchors": [
        "selector"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 43
    },
    {
      "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>  <li>apples</li>  <li>oranges</li>  <li>bananas</li>  <li class=\"selected\">pineapples</li></ul>\n```\n\n```\n// yields <li>pineapples</li>cy.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": 40
    },
    {
      "id": "api/commands/next#rules",
      "doc_id": "api/commands/next",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `.next()` requires being chained off a command that yields DOM element(s).\n\n### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)\n\n*   `.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 [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#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": 105
    },
    {
      "id": "api/commands/next#timeouts-learn-about-timeouts",
      "doc_id": "api/commands/next",
      "heading": "Timeouts Learn about timeouts",
      "heading_level": 3,
      "content_markdown": "### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `.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": [
        "timeouts-learn-about-timeouts"
      ],
      "path": "/llm/json/chunked/api/commands/next.json",
      "token_estimate": 41
    },
    {
      "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
    }
  ]
}