from selenium import webdriver from time import sleep from selenium.webdriver import ActionChains driver = webdriver.Firefox() action = ActionChains(driver) URL = r"C:\Users\I\Desktop\注册A.html" driver.get(URL) ele = driver.find_element_by_css_selector("#userA") # 鼠标的右键单击 action.context_click(ele).perform() # 鼠标的左键双击 ele.send_keys("admin") action.double_click(ele).perform() sleep(3) driver.quit() ---------------------------------------------------------------------- ----------------------------------------------------------------------
from selenium import webdriver from time import sleep from selenium.webdriver import ActionChains driver = webdriver.Firefox() action = ActionChains(driver) URL = r"C:\Users\I\Desktop\drop.html" driver.get(URL) # 鼠标的拖拽 source = driver.find_element_by_css_selector("#div1") target = driver.find_element_by_css_selector("#div2") # # 需求一:定位红色方框,蓝色方框,将红色方框拖拽覆盖到蓝色方框 action.drag_and_drop(source, target).perform() # 需求二:定位红色方框,并拖拽到180,120的位置 action.drag_and_drop_by_offset(source, 180, 120).perform() sleep(3) driver.quit()