键盘操作
键盘操作:
(1)删除键
(2)空格键
(3)回车键
(4)制表键
(5)全选、复制、剪切、粘贴
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.baidu.com")
input_element = driver.find_element_by_id('kw')
# 输入搜索内容
input_element.send_keys("python")
# ctrl + a 全选
input_element.send_keys(Keys.CONTROL, 'a')
time.sleep(2)
# 复制
input_element.send_keys(Keys.CONTROL, 'c')
time.sleep(2)
# 剪切
input_element.send_keys(Keys.CONTROL, 'x')
time.sleep(2)
# 粘贴
input_element.send_keys(Keys.CONTROL, 'v')
time.sleep(2)
# 空格键
input_element.send_keys(Keys.SPACE)
# 回车键
input_element.send_keys(Keys.ENTER)
time.sleep(2)
# 刷新
input_element.send_keys(Keys.F5)