Selenium WebDriver: I want to overwrite value in field instead of appending to it with sendKeys using Java

In WebDriver, if I use sendKeys it will append my string to the value that already exists in the field. I can’t clear it by using clear() method because the second I do that, the webpage will throw an error saying that it has to be between 10 and 100. So I can’t clear it or an error will be thrown before I can put in the new value using sendKeys, and if I sendKeys it just appends it to the value already there.

Is there anything in WebDriver that lets you overwrite the value in the field?

1 Like

You can also clear the field before sending it keys.

element.clear()
element.sendKeys("Some text here")
1 Like