selenium_mouse_drag_and_drop拖拽
# 导包
from selenium import webdriver
from time import sleep
# 获取浏览器驱动对象
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
driver = webdriver.Edge()
# 打开url
url = r"C:\Users\黄永生\Desktop\软件测试\P2C电子市场\web自动化_day01_课件+笔记+资料+代码\02_其他资料\注册A.html"
driver.get(url)
# 实例化并获取 ActionChains类
action = ActionChains(driver)
# 获取源元素
source = driver.find_element(By.CSS_SELECTOR,"#div1")
# 获取目标元素
target = driver.find_element(By.CSS_SELECTOR,"#div2")
sleep(2)
action.drag_and_drop(source, target).perform()
# 扩展 通过坐标偏移量执行
# action.drag_and_drop_by_offset(source, xoffset=360, yoffset=180).perform()
# 暂停 2
sleep(2)
# 关闭驱动对象
driver.quit()