There is a text box on a webpage. My aim is to fill it with some values, then clear it, and then fill it with some other value.
I can do the fill part with sendKeys() method. But how to clear the text from the textbox?
PS: I am using Selenium Python
1 Like
Hi Rebecca,
There are many ways by which you can clear the text in a text box (partially or fully), such as:
driver.get_element_by_id('foo').clear()
driver.find_element_by_id('foo').clear()
webElement.clear()
-
driver.find_element_by_id('foo').send_keys(Keys.CONTROL + "a");
driver.find_element_by_id('foo').send_keys(Keys.DELETE);
- For Partial:
webElement.sendKeys(Keys.BACK_SPACE) # do repeatedly, e.g. in while loop
driver.find_element_by_css_selector('foo').send_keys(u'\ue009' + u'\ue003')
- u’\ue009’ is a CONTROL
- u’\ue003’ is a BACK_SPACE
Hope this helps
3 Likes