Closed
Description
The .clear()
command isn't an alias to .type('{selectall}{backspace}')
since it doesn't behave the same. Since cypress 3.5 it's possible to type in any DOM element and if a typeable element gains focus during .type()
then cypress continues in that one. So if you .get()
a parent element of a typeable one, then .clear()
should work because it's supposed to be an alias to .type('{selectall}{backspace}')
as stated in the docs.
cy.clear() failed because it requires a valid clearable element.
The element cleared was:
> <div id="search-input-wrap" class="on">...</div>
A clearable element matches one of the following selectors:
'a[href]'
'area[href]'
'input'
'select'
'textarea'
'button'
'iframe'
'[tabindex]'
'[contenteditable]'
Current behavior:
.clear()
doesn't have the same behavior as .type('{selectall}{backspace}')
Desired behavior:
.clear()
to behave exactly like .type('{selectall}{backspace}')
Test code to reproduce
// Passes
it('test .type({selectall}{backspace})', () => {
cy.visit('https://docs.cypress.io/api/commands/clear.html#Syntax')
cy.get('#search-input-wrap').type('clear this')
cy.get('#search-input-wrap').type('{selectall}{backspace}').type('test')
})
// Fails
it('test .clear()', () => {
cy.visit('https://docs.cypress.io/api/commands/clear.html#Syntax')
cy.get('#search-input-wrap').type('clear this')
cy.get('#search-input-wrap').clear().type('test')
})
Versions
Tested on cypress 5.0 but most likely every version since 3.5