python中的ActionChain拖放

2024-04-20 10:56:57 发布

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

有人使用selenium webdriver ActionChain在漂亮的dnd页面上执行拖放操作吗?我可以使用下面的执行拖放一个例子页,但我不能让它在dnd页上的工作。它只是显示 “您已将物品提升到位 使用箭头键移动,空格键放下,escape键取消。 ““

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote(desired_capabilities=DesiredCapabilities.CHROME, command_executor='http://localhost:4444/wd/hub')

#drag and drop it does not work
driver.get("https://react-beautiful-dnd.netlify.com/iframe.html?selectedKind=board&selectedStory=simple")
loc = '//div[@class="quote-list__DropZone-sc-1fzhh8p-1 fuOOyc"]'
source_loc = driver.find_elements_by_xpath(loc)[1]
target_loc = driver.find_elements_by_xpath(loc)[2]

#error You have lifted an item in position
Use the arrow keys to move, space bar to drop, and escape to cancel.

#work for no problem
driver.get("http://jqueryui.com/resources/demos/droppable/default.html")
source_loc = driver.find_element_by_xpath('//div[@id="draggable"]')
target_loc = driver.find_element_by_xpath('//div[@id="droppable"]')
act = ActionChains(driver).drag_and_drop(source_loc, target_loc)
act.perform()

Tags: andfromimportdivsourcetargetbydriver