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()
本文来自博客园,作者:OTAKU_nicole,转载请注明原文链接:https://www.cnblogs.com/nicole-zhang/p/10383368.html