1.鼠标事件
需要导入:from selenium.webdriver.common.action_chains import ActionChains
1)右击
el = driver.find_element_by_id("kw") #定位元素
ActionChains(driver).context_click(el).perform() #右击
2)双击
el = driver.find_element_by_xpath("//div[@id='qrcode']/div/div[2]/p/b")
ActionChains(driver).double_click(el).perform()
3)拖拽
from selenium import webdriver
from selenium.webdriver import ActionChains
driver = webdriver.Firefox()
driver.get("http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable")
driver.maximize_window()
driver.switch_to.frame('iframeResult')
source = driver.find_element_by_id('draggable')
target = driver.find_element_by_id('droppable')
ActionChains(driver).drag_and_drop(source, target).perform() #拖拽
4)鼠标悬停
el = driver.find_element_by_link_text("设置")
ActionChains(driver).move_to_element(el).perform()
右击/双击实例:
拖拽实例:
鼠标悬停实例:
2.键盘事件
from selenium.webdriver.common.keys import Keys
send_keys(Keys.BACK_SPACE) 删除键(BackSpace)
send_keys(Keys.SPACE) 空格键(Space)
send_keys(Keys.TAB) 制表键(Tab)
send_keys(Keys.ESCAPE) 回退键(Esc)
send_keys(Keys.ENTER) 回车键(Enter)
send_keys(Keys.CONTROL, ‘a’) 全选(Ctrl+A)
send_keys(Keys.CONTROL, ‘c’) 复制(Ctrl+C)
send_keys(Keys.CONTROL, ‘x’) 剪切(Ctrl+X)
send_keys(Keys.CONTROL, ‘v’) 粘贴(Ctrl+V)
send_keys(Keys.F5) 键盘F5
标签:el,鼠标,selenium08,keys,driver,send,Keys,事件,ActionChains From: https://www.cnblogs.com/elaine888/p/18283659