from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.options import Options
driver = webdriver.Chrome()
# 鼠标点击:示例地址,http://sahitest.com/demo/clicks.htm
driver.get("http://sahitest.com/demo/clicks.htm")
# 单击按钮
el1 = driver.find_element_by_xpath("/html/body/form/input[3]")
ActionChains(driver).click(el1).perform()
# 双击按钮
el2 = driver.find_element_by_xpath("/html/body/form/input[2]")
ActionChains(driver).double_click(el2).perform()
# 鼠标右击
el3 = driver.find_element_by_xpath("/html/body/form/input[4]")
ActionChains(driver).context_click(el3).perform()
# 鼠标拖拽:示例地址,http://sahitest.com/demo/dragDropMooTools.htm
driver.get("http://sahitest.com/demo/dragDropMooTools.htm")
el1 = driver.find_element_by_id("dragger")
el2 = driver.find_element_by_xpath("/html/body/div[2]")
# 拖拽到元素位置
ActionChains(driver).drag_and_drop(el1, el2).perform()
# 拖住到坐标位置
ActionChains(driver).drag_and_drop_by_offset(el1, 300, 150).perform()
# 按住+松开实现拖拽
ActionChains(driver).click_and_hold(el1).release(el2).perform()
# 鼠标悬停:示例地址,https://sahitest.com/demo/mouseover.htm
driver.get("https://sahitest.com/demo/mouseover.htm")
el1 = driver.find_element_by_xpath("/html/body/form/input[1]")
ActionChains(driver).move_to_element(el1).perform()