Overview
HasClearButtonElement provides methods for interacting with the clear button that appears in Vaadin input components. The clear button allows users to quickly remove all input from a field, and this interface enables testing of that functionality.
Interface Location: org.vaadin.addons.dramafinder.element.shared.HasClearButtonElement
Methods
getClearButtonLocator()
part~="clear-button" selector.
Returns: Locator - Locator for the clear button part
clickClearButton()
isClearButtonVisible()
boolean - true if the clear button is visible, false otherwise
assertClearButtonVisible()
AssertionError if the clear button is not visible
assertClearButtonNotVisible()
AssertionError if the clear button is visible
Implementing Classes
The following element classes implementHasClearButtonElement:
TextFieldElement(and all subclasses:TextAreaElement,PasswordFieldElement,EmailFieldElement)AbstractNumberFieldElement(and its subclasses:NumberFieldElement,IntegerFieldElement,BigDecimalFieldElement)- All text input components that support the clear button feature
Usage Example
Implementation Details
Part Selector
The clear button is located using Vaadin’spart attribute system, which allows targeting internal parts of a shadow DOM component:
~= attribute selector matches when part contains the word “clear-button” in its space-separated list of values.
Clear Button Behavior
In Vaadin components:- The clear button is automatically hidden when the field is empty
- It appears when the field has any value
- Clicking it clears the field and hides the button again
- The clear button can be disabled via the
clear-button-visibleproperty
Testing Patterns
Test Clear Button Visibility
Test Clear Functionality
Test Clear Button in Search Flow
Test Clear Button with Validation
Test Clear Button Accessibility
Best Practices
Use Clear Button for User Simulation
When testing user workflows, prefer usingclickClearButton() over programmatic clear() to better simulate real user interaction:
Check Visibility Before Clicking
Always verify the clear button is visible before attempting to click it:Test Clear Button Disabled State
Some implementations may allow disabling the clear button. Test this if applicable:Related Interfaces
- HasValueElement - Provides the
clear()method for programmatic clearing - HasInputFieldElement - Parent interface for input fields with clear buttons
- HasPlaceholderElement - Often used together to guide users