{
  "doc": {
    "id": "api/commands/last",
    "title": "last | Cypress Documentation",
    "description": "Get the last DOM element within a set of DOM elements in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/last.md",
    "version": "24a73f8a97175663aaffd3b016289fb2a523a4ea",
    "updated_at": "2026-05-14T20:17:33.301Z",
    "headings": [
      {
        "id": "api/commands/last#last",
        "text": "last",
        "level": 1
      },
      {
        "id": "api/commands/last#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/last#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/last#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/last#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/last#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/last#no-args",
        "text": "No Args",
        "level": 3
      },
      {
        "id": "api/commands/last#get-the-last-list-item-in-a-list",
        "text": "Get the last list item in a list",
        "level": 4
      },
      {
        "id": "api/commands/last#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/last#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/last#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/last#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/last#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/last#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/last#syntax",
      "doc_id": "api/commands/last",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.last().last(options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('nav a').last() // Yield last link in nav\n```\n\n**Incorrect Usage**\n\n```\ncy.last() // Errors, cannot be chained off 'cy'cy.getCookies().last() // Errors, 'getCookies' does not yield DOM element\n```\n\n### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.last()`.\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 `.last()` 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*   `.last()` yields the new DOM element it found.\n*   `.last()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/last.json",
      "token_estimate": 168
    },
    {
      "id": "api/commands/last#usage",
      "doc_id": "api/commands/last",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('nav a').last() // Yield last link in nav\n```\n\n**Incorrect Usage**\n\n```\ncy.last() // Errors, cannot be chained off 'cy'cy.getCookies().last() // Errors, 'getCookies' does not yield DOM element\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/last.json",
      "token_estimate": 45
    },
    {
      "id": "api/commands/last#arguments",
      "doc_id": "api/commands/last",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.last()`.\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 `.last()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/last.json",
      "token_estimate": 79
    },
    {
      "id": "api/commands/last#examples",
      "doc_id": "api/commands/last",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### No Args\n\n#### Get the last list item in a list\n\n```\n<ul>  <li class=\"one\">Knick knack on my thumb</li>  <li class=\"two\">Knick knack on my shoe</li>  <li class=\"three\">Knick knack on my knee</li>  <li class=\"four\">Knick knack on my door</li></ul>\n```\n\n```\n// yields <li class=\"four\">Knick knack on my door</li>cy.get('li').last()\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/last.json",
      "token_estimate": 68
    },
    {
      "id": "api/commands/last#no-args",
      "doc_id": "api/commands/last",
      "heading": "No Args",
      "heading_level": 3,
      "content_markdown": "### No Args\n\n#### Get the last list item in a list\n\n```\n<ul>  <li class=\"one\">Knick knack on my thumb</li>  <li class=\"two\">Knick knack on my shoe</li>  <li class=\"three\">Knick knack on my knee</li>  <li class=\"four\">Knick knack on my door</li></ul>\n```\n\n```\n// yields <li class=\"four\">Knick knack on my door</li>cy.get('li').last()\n```\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/last.json",
      "token_estimate": 65
    },
    {
      "id": "api/commands/last#get-the-last-list-item-in-a-list",
      "doc_id": "api/commands/last",
      "heading": "Get the last list item in a list",
      "heading_level": 4,
      "content_markdown": "#### Get the last list item in a list\n\n```\n<ul>  <li class=\"one\">Knick knack on my thumb</li>  <li class=\"two\">Knick knack on my shoe</li>  <li class=\"three\">Knick knack on my knee</li>  <li class=\"four\">Knick knack on my door</li></ul>\n```\n\n```\n// yields <li class=\"four\">Knick knack on my door</li>cy.get('li').last()\n```\n",
      "section": "api",
      "anchors": [
        "get-the-last-list-item-in-a-list"
      ],
      "path": "/llm/json/chunked/api/commands/last.json",
      "token_estimate": 61
    },
    {
      "id": "api/commands/last#rules",
      "doc_id": "api/commands/last",
      "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*   `.last()` 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*   `.last()` 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*   `.last()` 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*   `.last()` 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*   `.last()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/last.json",
      "token_estimate": 105
    },
    {
      "id": "api/commands/last#timeouts-learn-about-timeouts",
      "doc_id": "api/commands/last",
      "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*   `.last()` 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*   `.last()` 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/last.json",
      "token_estimate": 41
    },
    {
      "id": "api/commands/last#command-log",
      "doc_id": "api/commands/last",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Find the last button in the form_**\n\n```\ncy.get('form').find('button').last()\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on `last` within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/last.json",
      "token_estimate": 48
    }
  ]
}