click() 鼠標點擊動作;
send_keys() 輸入字符串到文本輸入框動作;
clear() 清除文本框動作;
具體代碼:
# coding=utf-8 from selenium import webdriver driver = webdriver.Chrome() driver.maximize_window() driver.implicitly_wait(6) driver.get("https://www.baidu.com") driver.find_element_by_id("kw").send_keys("Selenium!") try: driver.find_element_by_id("kw").clear() print('test pass : clean successful') except Exception as e: print("Exception found",format(e))
參考文章:https://blog.csdn.net/u011541946/article/details/68927331