I\'ve got some tests where I\'m checking that the proper error message appears when text in certain fields are invalid. One check for validity is that a certain textarea el
I ran into a field where .clear() did not work. Using a combination of the first two answers worked for this field.
from selenium.webdriver.common.keys import Keys
#...your code (I was using python 3)
driver.find_element_by_id('foo').send_keys(Keys.CONTROL + "a");
driver.find_element_by_id('foo').send_keys(Keys.DELETE);
driver.find_element_by_id('foo').clear()
You can use
webElement.clear();
If this element is a text entry element, this will clear the value.
Note that the events fired by this event may not be as you'd expect. In particular, we don't fire any keyboard or mouse events. If you want to ensure keyboard events are fired, consider using something like sendKeys(CharSequence)
. E.g.:
webElement.sendKeys(Keys.BACK_SPACE); //do repeatedly, e.g. in while loop
or:
webElement.sendKeys(Keys.CONTROL + "a");
webElement.sendKeys(Keys.DELETE);