Skip to content
CodeKruPro

Clear a pre-filled field and type a new value

Automation taskEasy

Asked as: "The field already has a value. Your test types and ends up with both values joined. Why, and how do you fix it?" Typing adds to what is already there, so clear the field first.

Clear and Replace Text

Clear and Replace Text

The clear() method removes all text from an input field. Combine with sendKeys() to replace existing text.

On the Text Fields page, field #8 (ID: preFilledTextField) has a pre-filled value of "Codekru".

Task:

  1. Navigate to https://testkru.com/Elements/TextFields
  2. Find the pre-filled field
  3. Print its initial value
  4. Clear the field
  5. Type Selenium
  6. Print its new value

Expected output:

Before: Codekru
After: Selenium