Python ActionChains拖放方法工作不正常

2024-04-24 13:20:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用ActionChains拖放元素。但不能让它工作。你知道吗

环境:

因此有两种拖放方法:

拖放

按偏移量拖放

当我尝试使用offset时,它是有效的,但是当我使用常规的拖放时,它就不起作用了

driver = webdriver.Chrome()
driver.get("https://demoqa.com/")

sortable_button = driver.find_element(
    By.CSS_SELECTOR, "aside.widget:nth-of-type(1) li:nth-of-type(1)")
sortable_button.click()
items = driver.find_elements(By.CSS_SELECTOR, "#sortable li")
actions = ActionChains(driver)
actions.drag_and_drop_by_offset(items[0], 0, 200).perform()
# actions.drag_and_drop(items[0], items[4]).perform()
time.sleep(5)
driver.close()

Tags: httpscomactionsbydriveritemsbuttonfind