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

Viewed 101

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 greaterthan 1. 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 Answers

No, basically .clear() should work. but I have faced this issue several time it just does not work. Also what do you mean by

will throw an error saying that it has to greaterthan 1.

There's an alternate way, which is basically to do control + A to select all the text and then press backspace.

code :-

from selenium.webdriver.common.keys import Keys
element.send_keys(Keys.CONTROL, 'a')
element.send_keys(Keys.BACKSPACE)

where element is web element, in your case your input field.

Related