python+selenium小结2:通过clear()清除输入的内容
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from selenium import webdriver
import time
options = webdriver.ChromeOptions()
prefs = {
'profile.default_content_setting_values':
{
'notifications': 2
}
}
options.add_experimental_option('prefs', prefs) # 关掉浏览器左上角的通知提示
options.add_argument("disable-infobars") # 关闭'chrome正受到自动测试软件的控制'提示
driver = webdriver.Chrome(chrome_options=options)
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
s_input = driver.find_element_by_id("kw") # 通过ID查找元素
s_input.send_keys("酷酷木女侠")
s_enter = driver.find_element_by_id("su")
s_enter.click()
try:
time.sleep(5) #等待5s
s_input.clear() #通过clear()方法清除输入的内容
print("清除成功")
except Exception as e:
print("clear()出现问题了:" + format(e))
time.sleep(5)
driver.quit()
|