selenium的ActionChains鼠标事件:悬停、左右键单击、双击、拖动

#把元素ele1拖到ele2上
# ActionChains(driver).drag_and_drop(ele1,ele2).perform()
#右键单击
# ActionChains(driver).context_click(ele1).perform()
#左键单击
# ActionChains(driver).click(ele1).perform()
#悬停
# ActionChains(driver).move_to_element(ele1).perform()

悬停例子

from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
driver=webdriver.Chrome()
#打开百度
driver.get('https://www.baidu.com/')
#定位‘更多’元素
moreb=driver.find_element_by_name('tj_briicon')
#鼠标悬停在‘更多’元素上
ActionChains(driver).move_to_element(moreb).perform()
#再点击‘更多’里的‘图片’链接
driver.find_element_by_name('tj_img').click()
原文地址:https://www.cnblogs.com/docstrange/p/14523827.html