Class Clear

java.lang.Object
com.codeborne.selenide.commands.Clear
All Implemented Interfaces:
Command<SelenideElement>
Direct Known Subclasses:
AppiumClear, ClearWithShortcut

@ParametersAreNonnullByDefault public class Clear extends Object implements Command<SelenideElement>
Clean the input field value.

The standard Selenium method WebElement.clear() does not help in case of "tricky" inputs generated by Vue.js, React and other fancy frameworks.


That's why we need to clear the field value by emulating real user actions:

  1. Select the whole text
  2. press "Backspace"
  • Constructor Details

    • Clear

      public Clear()
  • Method Details

    • execute

      @Nonnull @CheckReturnValue public SelenideElement execute(SelenideElement proxy, WebElementSource locator, @Nullable Object[] args)
      Specified by:
      execute in interface Command<SelenideElement>
    • clearAndTrigger

      protected void clearAndTrigger(Driver driver, org.openqa.selenium.WebElement input)
      Clear the input content and trigger "change" and "blur" events

      This is the shortest keys combination I found in May 2022.
      It seems to work in Firefox, Chrome on Mac and on Linux smoothly.

    • blurSafely

      protected void blurSafely(Driver driver, org.openqa.selenium.WebElement input)
    • clear

      public void clear(Driver driver, org.openqa.selenium.WebElement input)
      Clear the input content without triggering "change" and "blur" events