'''键盘事件'''
driver.get("https://www.baidu.com/")
#导入keys
from selenium.webdriver.common.keys import Keys
#ctrl+/ #注释多行
driver.find_element_by_id("kw").send_keys("seleniumm")
#send_keys(Keys.BACK_SPACE) 删除键(BackSpace)
driver.find_element_by_id("kw").send_keys(Keys.BACK_SPACE)
# send_keys(Keys.SPACE) 空格键(Space)
driver.find_element_by_id("kw").send_keys(Keys.SPACE)
# send_keys(Keys.TAB) 制表键(Tab)
driver.find_element_by_id("kw").send_keys(Keys.TAB)
# send_keys(Keys.ESCAPE) 回退键(Esc)
driver.find_element_by_id("kw").send_keys(Keys.ESCAPE)
# send_keys(Keys.ENTER) 回车键(Enter)
driver.find_element_by_id("kw").send_keys(Keys.ENTER)
# send_keys(Keys.CONTROL,'a') 全选(Ctrl+A)
driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'a')
# send_keys(Keys.CONTROL,'c') 复制(Ctrl+C)
driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'c')
# send_keys(Keys.CONTROL,'x') 剪切(Ctrl+X)
driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'x')
# send_keys(Keys.CONTROL,'v') 粘贴(Ctrl+V)
driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'v')
# send_keys(Keys.F1) 键盘F1
# ……
# send_keys(Keys.F5)键盘F5
driver.find_element_by_id("kw").send_keys(Keys.F5)
# …
# send_keys(Keys.F12) 键盘F12
driver.find_element_by_id("kw").send_keys(Keys.F12)
'''鼠标事件'''
driver.get("https://www.baidu.com/")
#导入ActionChains类
from selenium.webdriver.common.action_chains import ActionChains
driver.find_element_by_id("kw").send_keys("乏善可陈")
#获取元素
ele = driver.find_element_by_id("su")
ele1 = driver.find_element_by_link_text("设置")
#右击 context_click()
ActionChains(driver).context_click(ele).perform() #perform执行
#双击 double_click()
ActionChains(driver).double_click(ele).perform()
#悬停 move_to_element()
ActionChains(driver).move_to_element(ele1).perform()
driver.find_element_by_link_text("搜索设置").click()
#拖放 (ps:例子未实现)
ele3 = driver.find_element_by_id("txtUserName") #源位置
ele4 = driver.find_element_by_id("txtUserPass") #移动到的目标位置
ActionChains(driver).drag_and_drop(ele3,ele4).perform()