mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-18 22:28:38 -05:00
2.3 KiB
2.3 KiB
title, comments, description
| title | comments | description |
|---|---|---|
| clear | true |
Clears a value of an <input> or <textarea>. Under the hood this is actually a shortcut for writing:
cy.type("{selectall}{backspace}")
Prior to clearing, if the element isn't currently focused, Cypress will issue a click on the element, which will cause the element to receive focus.
The following events are fired during clear: keydown, keypress, textInput, input, keyup.
beforeinput is not fired even though it is in the spec because no browser has adopted it.
| Returns | the element that was typed into |
| Timeout | cy.clear will retry for the duration of the defaultCommandTimeout or the duration of the timeout specified in the command's options. |
cy.clear()
Clears the value of an <input> or <textarea>.
Options
Pass in an options object to change the default behavior of cy.clear.
cy.clear( options )
| Option | Default | Notes |
|---|---|---|
force |
false |
Forces clear, disables error checking prior to clear |
interval |
16 |
Interval which to retry type |
timeout |
defaultCommandTimeout |
Total time to retry the type |
log |
true |
whether to display command in command log |
Usage
Clear the input and type a new value.
<input name="name" value="John Doe" />
// clears the existing value first before typing
cy.get("input[name='name']").clear().type("Jane Lane")
Command Log
Clear the input and type a new value
cy.get("input[name='name']").clear().type("Jane Lane")
The commands above will display in the command log as:
When clicking on clear within the command log, the console outputs the following: