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

True_Blue picture True_Blue · Jul 14, 2010 · Viewed 129.8k times · Source

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?

Answer

Tim Banks picture Tim Banks · Apr 21, 2011

You can also clear the field before sending it keys.

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