Skip to main content

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()

Returns a locator for the clear button element using the part~="clear-button" selector. Returns: Locator - Locator for the clear button part

clickClearButton()

Clicks the clear button to remove the field’s value.

isClearButtonVisible()

Checks whether the clear button is currently visible. The clear button is typically only visible when the field has a value. Returns: boolean - true if the clear button is visible, false otherwise

assertClearButtonVisible()

Asserts that the clear button is visible. Throws: AssertionError if the clear button is not visible

assertClearButtonNotVisible()

Asserts that the clear button is not visible. Throws: AssertionError if the clear button is visible

Implementing Classes

The following element classes implement HasClearButtonElement:
  • 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’s part attribute system, which allows targeting internal parts of a shadow DOM component:
The ~= 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-visible property

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 using clickClearButton() 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:
Or use assertions:

Test Clear Button Disabled State

Some implementations may allow disabling the clear button. Test this if applicable: