clear selenium action chains

Viewed 5463

I am using Python 3.5 with selenium 3.4.3

selenium.webdriver.remote.webelement has a clear() function that can clear the text in an input element.

I need to call this function from an ActionChains. But, as the documentation says, this functions seems not to be part of this class

How can I clear() an input element from an ActionChain?

3 Answers

I had an input address form, where several words text had already been entered by browser automatically. And I needed to clear the form, but methods web_element.clear() and ActionChains(driver).key_press(Keys.CONTROL).key_press('a').send_keys(Key.BACKSPACE) didn't worked (the latter highlights the whole page). The next code did worked:

ActionChains(driver).move_to_element(web_element).double_click().click_and_hold().send_keys(Keys.CLEAR).send_keys(text).perform()

The trick is that I used .double_click() and .click_and_hold() together and then cleared the field with .send_keys(Keys.CLEAR) (BACKSPACE and DELETE also work)

Related