Class Clear

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

public class Clear extends FluentCommand
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

      protected void execute(WebElementSource locator, Object @Nullable [] args)
      Specified by:
      execute in class FluentCommand
    • 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

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