selenium鼠标将一个元素拖动到另一元素中

import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable")
driver.implicitly_wait(30)

# 切换iframe(要定位的元素在另一个iframe框架中)
driver.switch_to.frame(driver.find_element(by=By.XPATH, value="//iframe[@id='iframeResult']"))

s = WebDriverWait(driver, 30, 0.5).until(
    EC.visibility_of_element_located((By.ID, 'draggable'))
)
e = WebDriverWait(driver, 30, 0.5).until(
    EC.visibility_of_element_located((By.ID, 'droppable'))
)

# ------------鼠标操作--将一个元素拖动到另一个元素中------------
action = ActionChains(driver)
# 添加拖动元素动作
action.drag_and_drop(s, e)
# 执行动作
action.perform()

# 为了看效果 等5秒之后再退出
time.sleep(5)
driver.quit()

 

上一篇:Python_expected_conditions模块用法简介


下一篇:谷粒学院-12-多表查询