gpt4 book ai didi

node.js - 使用 Nightwatch 进行拖放

转载 作者:太空宇宙 更新时间:2023-11-04 01:33:02 34 4
gpt4 key购买 nike

我试图使用 selenium 在 Nightwatch 中使用拖放操作将元素拖放到特定位置,但是当我将多个元素拖放到同一个可放置元素时,它会重叠。

var dragAndDrop = require('html-dnd').codeForSelectors;  
this.dragModule = function (draggable, droppable, posX, posY) {
browser.pause(3000);
var dndSimulateConfig = { dropOffset: [posX, posY] };
browser
.execute(dragAndDrop, [draggable, droppable, dndSimulateConfig])
.pause(2000);
};

它不应该与我想要的特定坐标重叠

最佳答案

locator1: can be xpath (or cssSelector) of your first element you want to drag locator2: can be xpath (or cssSelector ) is where you want to drop

this is tried and tested code, might be you need to little modify but it's working great for me.

return browser
.useXpath()
.moveToElement(locator1, XOffset1, Yoffset1)
.pause(100) // if you want to give wait
.mouseButtonDown(0) // press click, down
.moveToElement(locator2, XOffset2, Yoffset2) // move to element
.mouseButtonUp(0); // press release , up

read here docs- http://nightwatchjs.org/api and search for "moveToElement"

how to call:

myFunction moveToSpecificElement(locator, x, y) {
return browser
.moveToElement(locator, x, y, function (result) {
this.assert.equal("your assertion goes here");
});
}

关于node.js - 使用 Nightwatch 进行拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55450436/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com