python自动化测试——鼠标事件(ActionChains类)

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.***.cn")

ele = driver.find_element(By.CSS_SELECTOR,"***")
target = driver.find_element(By.CSS_SELECTOR,"***")
#鼠标悬停
ActionChains(driver).move_to_element(ele).perform()

#右键
ActionChains(driver).context_click(ele).perform()

#双击
ActionChains(driver).double_click(ele).perform()

#拖动到目标位置
ActionChains(driver).drag_and_drop(ele,target).perform()

#向右下拖拽
ActionChains(driver).click_and_hold(ele).move_by_offset(xoffset=500, yoffset=500).release().perform()
#向右拖拽
ActionChains(driver).click_and_hold(ele).move_by_offset(xoffset=500, yoffset=0).release().perform()
#向下拖拽
ActionChains(driver).click_and_hold(ele).move_by_offset(xoffset=0, yoffset=500).release().perform()

driver.quit()

 

posted @ 2019-02-15 14:24  OTAKU_nicole  阅读(410)  评论(0编辑  收藏  举报