driver.find_element_by_xpath.clear () can not empty the input box defaults

Input box with default values, want to delete the default value, to fill new content, using the clear () again send_keys (),

Found in this way can not be cleared, only added new content after the default value.

Internet search a bit, there are two solutions, as follows:

Method One :

Double-click the first, directly after send_keys (), no clear ()

Defects: Double-click may not be able to select all content

ele = driver.find_element_by_xpath('xxx')
ActionChains(driver).double_click(ele).perform()
ele.send_keys('abc')

Method Two :

Selected by the full keyboard, and then directly send_keys (), no clear ()

ele = driver.find_element_by_xpath('xxx')
ele.send_keys(Keys.CONTROL, 'a')
ele.send_keys('abc')




Guess you like

Origin www.cnblogs.com/jjstrip/p/11990447.html