{
  "doc": {
    "id": "api/commands/clear",
    "title": "cy.clear()",
    "description": "Clear the value of an input, textarea, or contenteditable element in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/clear.md",
    "version": "c4ad6f88c531de58221c73dd91a75af7138334b8",
    "updated_at": "2026-11-10T01:15:02.829Z",
    "headings": [
      {
        "id": "api/commands/clear#clear",
        "text": "clear",
        "level": 1
      },
      {
        "id": "api/commands/clear#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/clear#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/clear#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/clear#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/clear#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/clear#no-args",
        "text": "No Args",
        "level": 3
      },
      {
        "id": "api/commands/clear#clear-the-input-and-type-a-new-value",
        "text": "Clear the input and type a new value",
        "level": 4
      },
      {
        "id": "api/commands/clear#clear-an-input-and-confirm-its-empty",
        "text": "Clear an input and confirm it's empty",
        "level": 4
      },
      {
        "id": "api/commands/clear#multiple-elements",
        "text": "Multiple elements",
        "level": 3
      },
      {
        "id": "api/commands/clear#clear-every-text-input-in-a-form",
        "text": "Clear every text input in a form",
        "level": 4
      },
      {
        "id": "api/commands/clear#contenteditable-elements",
        "text": "Contenteditable elements",
        "level": 3
      },
      {
        "id": "api/commands/clear#clear-a-rich-text-editor",
        "text": "Clear a rich text editor",
        "level": 4
      },
      {
        "id": "api/commands/clear#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/clear#actionability",
        "text": "Actionability",
        "level": 3
      },
      {
        "id": "api/commands/clear#the-element-must-first-reach-actionability",
        "text": "The element must first reach actionability",
        "level": 4
      },
      {
        "id": "api/commands/clear#events",
        "text": "Events",
        "level": 3
      },
      {
        "id": "api/commands/clear#clear-doesnt-fire-change-until-the-element-loses-focus",
        "text": ".clear() doesn't fire change until the element loses focus",
        "level": 4
      },
      {
        "id": "api/commands/clear#documentation",
        "text": "Documentation",
        "level": 3
      },
      {
        "id": "api/commands/clear#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/clear#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/clear#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/clear#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/clear#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/clear#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/clear#syntax",
      "doc_id": "api/commands/clear",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.clear()\n.clear(options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.get('[type=\"text\"]').clear() // Clear text input\ncy.get('textarea').type('Hi!')\ncy.get('textarea').clear() // Clear textarea\ncy.focused().clear() // Clear focused input/textarea\ncy.get('[contenteditable]').clear() // Clear contenteditable element\ncy.get('form input[type=\"text\"]').clear() // Clear every text input in a form\n```\n\n**Incorrect Usage**\n\n```\ncy.clear() // Errors, cannot be chained off 'cy'\ncy.get('nav').clear() // Errors, 'get' doesn't yield a clearable element\ncy.get('[type=\"checkbox\"]').clear() // Errors, checkboxes aren't clearable\ncy.clock().clear() // Errors, 'clock' does not yield DOM elements\n```\n\n### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.clear()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `animationDistanceThreshold` | [`animationDistanceThreshold`](/llm/markdown/app/references/configuration.md#Actionability) | The distance in pixels an element must exceed over time to be [considered animating](/llm/markdown/app/core-concepts/interacting-with-elements.md#Animations). |\n| `force` | `false` | Forces the action, disables [waiting for actionability](#Assertions) |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `scrollBehavior` | [`scrollBehavior`](/llm/markdown/app/references/configuration.md#Actionability) | Viewport position to where an element [should be scrolled](/llm/markdown/app/core-concepts/interacting-with-elements.md#Scrolling) before executing the command. Accepts a single alignment, a per-axis `{ block, inline }` object, or `false`. |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `.clear()` to resolve before [timing out](#Timeouts) |\n| `waitForAnimations` | [`waitForAnimations`](/llm/markdown/app/references/configuration.md#Actionability) | Whether to wait for elements to [finish animating](/llm/markdown/app/core-concepts/interacting-with-elements.md#Animations) before executing the command. |\n\n### Yields\n\n*   `.clear()` yields the same subject it was given.\n*   It is [unsafe](/llm/markdown/app/core-concepts/retry-ability.md#Only-queries-are-retried) to chain further commands that rely on the subject after `.clear()`.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 328
    },
    {
      "id": "api/commands/clear#usage",
      "doc_id": "api/commands/clear",
      "heading": "Usage",
      "heading_level": 3,
      "content_markdown": "### Usage\n\n**Correct Usage**\n\n```\ncy.get('[type=\"text\"]').clear() // Clear text input\ncy.get('textarea').type('Hi!')\ncy.get('textarea').clear() // Clear textarea\ncy.focused().clear() // Clear focused input/textarea\ncy.get('[contenteditable]').clear() // Clear contenteditable element\ncy.get('form input[type=\"text\"]').clear() // Clear every text input in a form\n```\n\n**Incorrect Usage**\n\n```\ncy.clear() // Errors, cannot be chained off 'cy'\ncy.get('nav').clear() // Errors, 'get' doesn't yield a clearable element\ncy.get('[type=\"checkbox\"]').clear() // Errors, checkboxes aren't clearable\ncy.clock().clear() // Errors, 'clock' does not yield DOM elements\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 96
    },
    {
      "id": "api/commands/clear#arguments",
      "doc_id": "api/commands/clear",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.clear()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `animationDistanceThreshold` | [`animationDistanceThreshold`](/llm/markdown/app/references/configuration.md#Actionability) | The distance in pixels an element must exceed over time to be [considered animating](/llm/markdown/app/core-concepts/interacting-with-elements.md#Animations). |\n| `force` | `false` | Forces the action, disables [waiting for actionability](#Assertions) |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `scrollBehavior` | [`scrollBehavior`](/llm/markdown/app/references/configuration.md#Actionability) | Viewport position to where an element [should be scrolled](/llm/markdown/app/core-concepts/interacting-with-elements.md#Scrolling) before executing the command. Accepts a single alignment, a per-axis `{ block, inline }` object, or `false`. |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `.clear()` to resolve before [timing out](#Timeouts) |\n| `waitForAnimations` | [`waitForAnimations`](/llm/markdown/app/references/configuration.md#Actionability) | Whether to wait for elements to [finish animating](/llm/markdown/app/core-concepts/interacting-with-elements.md#Animations) before executing the command. |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 189
    },
    {
      "id": "api/commands/clear#examples",
      "doc_id": "api/commands/clear",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### No Args\n\n#### Clear the input and type a new value\n\n```\ncy.get('textarea').clear()\ncy.get('textarea').type('Hello, World')\n```\n\n#### Clear an input and confirm it's empty\n\nEnd the chain at `.clear()`, then start a new chain for the assertion. The new [`cy.get()`](/llm/markdown/api/commands/get.md) re-queries the input, so the assertion still passes if your app re-renders it after the clear.\n\n```\ncy.get('input[name=\"email\"]').clear()\ncy.get('input[name=\"email\"]').should('have.value', '')\n```\n\nChaining the assertion directly off `.clear()` retries only against the element `.clear()` acted on. If that element is replaced in the DOM, the assertion keeps checking the detached copy. See [Actions should be at the end of chains](/llm/markdown/app/core-concepts/retry-ability.md#Actions-should-be-at-the-end-of-chains-not-the-middle).\n\n### Multiple elements\n\n#### Clear every text input in a form\n\n`.clear()` clears each element in the subject in order, then yields them all.\n\n```\ncy.get('#signup-form input[type=\"text\"]').clear()\ncy.get('#signup-form input[type=\"text\"]').should(($inputs) => {\n  $inputs.each((i, input) => {\n    expect(input).to.have.value('')\n  })\n})\n```\n\nA `have.value` assertion on several elements checks only the first one's value, so check each element inside a `.should()` callback. Cypress retries the callback and re-runs the `cy.get()` query, so it always checks the inputs currently on the page.\n\n### Contenteditable elements\n\n#### Clear a rich text editor\n\nTarget the element that carries the `contenteditable` attribute, then type new content into it.\n\n```\ncy.get('[contenteditable]').clear()\ncy.get('[contenteditable]').type('A fresh start')\n```\n\nRich text editors often manage their own selection and DOM. The [`.type()` notes on contenteditable elements](/llm/markdown/api/commands/type.md#Contenteditable-Elements) cover how to work with them.\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 308
    },
    {
      "id": "api/commands/clear#no-args",
      "doc_id": "api/commands/clear",
      "heading": "No Args",
      "heading_level": 3,
      "content_markdown": "### No Args\n\n#### Clear the input and type a new value\n\n```\ncy.get('textarea').clear()\ncy.get('textarea').type('Hello, World')\n```\n\n#### Clear an input and confirm it's empty\n\nEnd the chain at `.clear()`, then start a new chain for the assertion. The new [`cy.get()`](/llm/markdown/api/commands/get.md) re-queries the input, so the assertion still passes if your app re-renders it after the clear.\n\n```\ncy.get('input[name=\"email\"]').clear()\ncy.get('input[name=\"email\"]').should('have.value', '')\n```\n\nChaining the assertion directly off `.clear()` retries only against the element `.clear()` acted on. If that element is replaced in the DOM, the assertion keeps checking the detached copy. See [Actions should be at the end of chains](/llm/markdown/app/core-concepts/retry-ability.md#Actions-should-be-at-the-end-of-chains-not-the-middle).\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 133
    },
    {
      "id": "api/commands/clear#clear-an-input-and-confirm-its-empty",
      "doc_id": "api/commands/clear",
      "heading": "Clear an input and confirm it's empty",
      "heading_level": 4,
      "content_markdown": "#### Clear an input and confirm it's empty\n\nEnd the chain at `.clear()`, then start a new chain for the assertion. The new [`cy.get()`](/llm/markdown/api/commands/get.md) re-queries the input, so the assertion still passes if your app re-renders it after the clear.\n\n```\ncy.get('input[name=\"email\"]').clear()\ncy.get('input[name=\"email\"]').should('have.value', '')\n```\n\nChaining the assertion directly off `.clear()` retries only against the element `.clear()` acted on. If that element is replaced in the DOM, the assertion keeps checking the detached copy. See [Actions should be at the end of chains](/llm/markdown/app/core-concepts/retry-ability.md#Actions-should-be-at-the-end-of-chains-not-the-middle).\n",
      "section": "api",
      "anchors": [
        "clear-an-input-and-confirm-its-empty"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 111
    },
    {
      "id": "api/commands/clear#multiple-elements",
      "doc_id": "api/commands/clear",
      "heading": "Multiple elements",
      "heading_level": 3,
      "content_markdown": "### Multiple elements\n\n#### Clear every text input in a form\n\n`.clear()` clears each element in the subject in order, then yields them all.\n\n```\ncy.get('#signup-form input[type=\"text\"]').clear()\ncy.get('#signup-form input[type=\"text\"]').should(($inputs) => {\n  $inputs.each((i, input) => {\n    expect(input).to.have.value('')\n  })\n})\n```\n\nA `have.value` assertion on several elements checks only the first one's value, so check each element inside a `.should()` callback. Cypress retries the callback and re-runs the `cy.get()` query, so it always checks the inputs currently on the page.\n",
      "section": "api",
      "anchors": [
        "multiple-elements"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 104
    },
    {
      "id": "api/commands/clear#clear-every-text-input-in-a-form",
      "doc_id": "api/commands/clear",
      "heading": "Clear every text input in a form",
      "heading_level": 4,
      "content_markdown": "#### Clear every text input in a form\n\n`.clear()` clears each element in the subject in order, then yields them all.\n\n```\ncy.get('#signup-form input[type=\"text\"]').clear()\ncy.get('#signup-form input[type=\"text\"]').should(($inputs) => {\n  $inputs.each((i, input) => {\n    expect(input).to.have.value('')\n  })\n})\n```\n\nA `have.value` assertion on several elements checks only the first one's value, so check each element inside a `.should()` callback. Cypress retries the callback and re-runs the `cy.get()` query, so it always checks the inputs currently on the page.\n",
      "section": "api",
      "anchors": [
        "clear-every-text-input-in-a-form"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 100
    },
    {
      "id": "api/commands/clear#contenteditable-elements",
      "doc_id": "api/commands/clear",
      "heading": "Contenteditable elements",
      "heading_level": 3,
      "content_markdown": "### Contenteditable elements\n\n#### Clear a rich text editor\n\nTarget the element that carries the `contenteditable` attribute, then type new content into it.\n\n```\ncy.get('[contenteditable]').clear()\ncy.get('[contenteditable]').type('A fresh start')\n```\n\nRich text editors often manage their own selection and DOM. The [`.type()` notes on contenteditable elements](/llm/markdown/api/commands/type.md#Contenteditable-Elements) cover how to work with them.\n",
      "section": "api",
      "anchors": [
        "contenteditable-elements"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 68
    },
    {
      "id": "api/commands/clear#clear-a-rich-text-editor",
      "doc_id": "api/commands/clear",
      "heading": "Clear a rich text editor",
      "heading_level": 4,
      "content_markdown": "#### Clear a rich text editor\n\nTarget the element that carries the `contenteditable` attribute, then type new content into it.\n\n```\ncy.get('[contenteditable]').clear()\ncy.get('[contenteditable]').type('A fresh start')\n```\n\nRich text editors often manage their own selection and DOM. The [`.type()` notes on contenteditable elements](/llm/markdown/api/commands/type.md#Contenteditable-Elements) cover how to work with them.\n",
      "section": "api",
      "anchors": [
        "clear-a-rich-text-editor"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 64
    },
    {
      "id": "api/commands/clear#notes",
      "doc_id": "api/commands/clear",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Actionability\n\n#### The element must first reach actionability\n\n`.clear()` is an \"action command\" that follows all the rules of [Actionability](/llm/markdown/app/core-concepts/interacting-with-elements.md).\n\n### Events\n\n#### `.clear()` doesn't fire `change` until the element loses focus\n\n`.clear()` fires the same keyboard and `input` events a user's keystrokes do. An `input` or `textarea` fires `change` when it loses focus after its value changes, so `.clear()` alone doesn't trigger it. If your app validates or saves on `change`, follow `.clear()` with [`.blur()`](/llm/markdown/api/commands/blur.md), or with any command that moves focus elsewhere, such as clicking another element:\n\n```\ncy.get('input[name=\"email\"]').clear()\ncy.get('input[name=\"email\"]').blur()\ncy.contains('Email is required').should('be.visible')\n```\n\n### Documentation\n\n`.clear()` is an alias for [`.type('{selectall}{del}')`](/llm/markdown/api/commands/type.md) that also works on a subject with more than one element.\n\nRead the [`.type()`](/llm/markdown/api/commands/type.md) documentation for more details.\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 167
    },
    {
      "id": "api/commands/clear#events",
      "doc_id": "api/commands/clear",
      "heading": "Events",
      "heading_level": 3,
      "content_markdown": "### Events\n\n#### `.clear()` doesn't fire `change` until the element loses focus\n\n`.clear()` fires the same keyboard and `input` events a user's keystrokes do. An `input` or `textarea` fires `change` when it loses focus after its value changes, so `.clear()` alone doesn't trigger it. If your app validates or saves on `change`, follow `.clear()` with [`.blur()`](/llm/markdown/api/commands/blur.md), or with any command that moves focus elsewhere, such as clicking another element:\n\n```\ncy.get('input[name=\"email\"]').clear()\ncy.get('input[name=\"email\"]').blur()\ncy.contains('Email is required').should('be.visible')\n```\n",
      "section": "api",
      "anchors": [
        "events"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 101
    },
    {
      "id": "api/commands/clear#clear-doesnt-fire-change-until-the-element-loses-focus",
      "doc_id": "api/commands/clear",
      "heading": ".clear() doesn't fire change until the element loses focus",
      "heading_level": 4,
      "content_markdown": "#### `.clear()` doesn't fire `change` until the element loses focus\n\n`.clear()` fires the same keyboard and `input` events a user's keystrokes do. An `input` or `textarea` fires `change` when it loses focus after its value changes, so `.clear()` alone doesn't trigger it. If your app validates or saves on `change`, follow `.clear()` with [`.blur()`](/llm/markdown/api/commands/blur.md), or with any command that moves focus elsewhere, such as clicking another element:\n\n```\ncy.get('input[name=\"email\"]').clear()\ncy.get('input[name=\"email\"]').blur()\ncy.contains('Email is required').should('be.visible')\n```\n",
      "section": "api",
      "anchors": [
        "clear-doesnt-fire-change-until-the-element-loses-focus"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 99
    },
    {
      "id": "api/commands/clear#rules",
      "doc_id": "api/commands/clear",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `.clear()` requires being chained off a command that yields DOM element(s).\n*   `.clear()` requires every element in the subject to be one of the following:\n    *   a `textarea`\n    *   an `input` of type `text`, `password`, `email`, `number`, `search`, `tel`, `url`, `date`, `datetime`, `datetime-local`, `month`, `week`, or `time` (an `input` with no `type` attribute counts as `text`)\n    *   an element whose content is editable, such as one with a `contenteditable` attribute\n\n### Assertions\n\n*   `.clear()` automatically waits for the element to reach an [actionable state](/llm/markdown/app/core-concepts/interacting-with-elements.md)\n*   `.clear()` automatically [retries](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed\n\n### Timeouts\n\n*   `.clear()` can time out waiting for the element to reach an [actionable state](/llm/markdown/app/core-concepts/interacting-with-elements.md).\n*   `.clear()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 169
    },
    {
      "id": "api/commands/clear#requirements",
      "doc_id": "api/commands/clear",
      "heading": "Requirements",
      "heading_level": 3,
      "content_markdown": "### Requirements\n\n*   `.clear()` requires being chained off a command that yields DOM element(s).\n*   `.clear()` requires every element in the subject to be one of the following:\n    *   a `textarea`\n    *   an `input` of type `text`, `password`, `email`, `number`, `search`, `tel`, `url`, `date`, `datetime`, `datetime-local`, `month`, `week`, or `time` (an `input` with no `type` attribute counts as `text`)\n    *   an element whose content is editable, such as one with a `contenteditable` attribute\n",
      "section": "api",
      "anchors": [
        "requirements"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 97
    },
    {
      "id": "api/commands/clear#command-log",
      "doc_id": "api/commands/clear",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Clear the input and type a new value_**\n\n```\ncy.get('input[name=\"name\"]').clear()\ncy.get('input[name=\"name\"]').type('Jane Lane')\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on `clear` within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/clear.json",
      "token_estimate": 52
    }
  ]
}