常规清除文字输入框字符的方法clear()。
练习场景:在百度首页输入框删除文字
具体代码:
# coding=utf-8 import time from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() driver.maximize_window() driver.get('https://www.baidu.com/') element = driver.find_element_by_id('kw') element.send_keys("Selenium automation") print('输入成功') time.sleep(1) element.send_keys(Keys.CONTROL+'a') print('全选成功') element.send_keys(Keys.BACKSPACE) print('删除成功')
参考文章:https://blog.csdn.net/u011541946/article/details/70037102