鍵盤操作:
(1)刪除鍵
(2)空格鍵
(3)Enter鍵
(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)
# Enter鍵
input_element.send_keys(Keys.ENTER)
time.sleep(2)
# 重新整理
input_element.send_keys(Keys.F5)