This only happens on Safari with SafariDriver:
For a textinput element, clear() can clear the field indeed, but the following values sent using sendKeys() are actually extended with the original value.
Example:
Start -- input value: 1
input.clear() -- input value: empty
input.sendKeys(2) -- input value: 12
Also tried
sendKeys(Key.HOME,Key.chord(Key.SHIFT,Key.END),newVal)
to select all and replace, but this simply not working. Nothing was selected.
Any suggestion is appreciated.
Try to click
element first and then use clear()
method to clear text, it works for me many times may be for you also:
WebElement myInputElement= driver.findElement("Locator value");
myInputElement.click();
myInputElement.clear();
myInputElement.sendKeys('Testing');