如何触发.onDragEnter
功能,就像这个
// init
// open page, wait load
const actions = await driver.actions();
const da1 = await driver.findElement(By.css('#todrag > span'));
const da2 = await driver.findElement(By.css('#mydropzone'));
await actions.dragAndDrop(da1, da2).perform();
.dragAndDrop()
不工作,与:
await actions.move({origin: da1}).press().move({origin: da2}).release().perform();
听起来像个bug
特别是因为我的左键点击后.perform()
,它卡住了(有时)&生成[Draggable 1]
项目/对象到我真正的一个鼠标图标
#回答cruisepandey祝辞您确定您没有丢失.build.perform()
吗?
.build.perform(); aaTypeError: Cannot read property 'perform' of undefined
.build().perform(); TypeError: actions.dragAndDrop(...).build is not a function
.build.perform(); aaTypeError: Cannot read property 'perform' of undefined
.build().perform(); TypeError: actions.move(...).press(...).move(...).release(...).build is not a function
这不是很清楚你想做什么,但我理解da2点击和移动!!如果你需要找到并点击去https://selenium-python.readthedocs.io/locating-elements.html#:~:text=find_element_by_class_name-,find_element_by_css_selector,-To%20find%20multiple
请下载drag_and_drop_helper.js
,然后再试一下:
with open("drag_and_drop_helper.js") as f:
js = f.read()
driver.execute_script(js + "$('#todrag > span').simulateDragDrop({ dropTarget: '#mydropzone'});")
更多的解释可以在这里阅读