导入鼠标事件动作链
from selenium.webdriver.common.action_chains import ActionChains
定位到要操作的元素
right_click = driver.find_element_by_id("XX")
1. 鼠标右击
ActionChains(driver).context_click(right_click).perform()
2. 鼠标悬浮
ActionChains(driver).move_to_element(right_click).perform()
3. 鼠标双击
ActionChains(driver).double_click(right_click).perform()
4. 鼠标拖放
source = driver.find_element_by_id("XX") target = driver.find_element_by_id("XX") ActionChains(driver).drag_and_drop(source , target).perform()
5. 连续输入框输入内容
ac = ActionChains(driver) t1 = driver.find_element_by_id('t1') t2 = driver.find_element_by_id('t2') t3 = driver.find_element_by_id('t3') ac.click(t1).send_keys('1').click(t2).send_keys('2').click(t2).send_keys('3').perform() 在元素t1 t2 t3里连续输入1 2 3