正文
driver.find_element_by_xpath.clear()无法清空输入框默认值
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
输入框带默认值,想删除默认值,填写新内容,使用clear()再send_keys(),
发现这种方式无法清除,只会在默认值后面追加新的内容。
上网搜了一下,有两种解决方案,如下:
方法一:
先双击,后直接send_keys(), 不用clear()
缺陷: 双击不一定能选中所有内容
ele = driver.find_element_by_xpath('xxx')
ActionChains(driver).double_click(ele).perform()
ele.send_keys('abc')
方法二:
通过键盘操作全选,然后直接send_keys(), 不用clear()
ele = driver.find_element_by_xpath('xxx')
ele.send_keys(Keys.CONTROL, 'a')
ele.send_keys('abc')