Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Nightwatch.js:拖放_Selenium_Drag And Drop_Nightwatch.js - Fatal编程技术网

Selenium Nightwatch.js:拖放

Selenium Nightwatch.js:拖放,selenium,drag-and-drop,nightwatch.js,Selenium,Drag And Drop,Nightwatch.js,我正在尝试使用Nightwatch.js 0.8.18、Selenium Server 2.53.0和Chrome驱动程序2.21.2测试拖放操作 基本上,我采用的方法是–即:类似于 .moveToElement('some-xpath-expression', 10, 10) .pause(100) .mouseButtonDown(0) .pause(100) .moveToElement('other-xpath-expression', 30, 30) .pause(100) .mous

我正在尝试使用Nightwatch.js 0.8.18、Selenium Server 2.53.0和Chrome驱动程序2.21.2测试拖放操作

基本上,我采用的方法是–即:类似于

.moveToElement('some-xpath-expression', 10, 10)
.pause(100)
.mouseButtonDown(0)
.pause(100)
.moveToElement('other-xpath-expression', 30, 30)
.pause(100)
.mouseButtonUp(0)
光标移动到要拖动的元素(可通过鼠标所在图标的
:hover
样式感知),但随后什么也不会发生。在我看来,
mouseButtonDown()
操作没有效果。(但谁能肯定呢?)

如果我使用Firefox而不是Chrome,这没有什么区别——行为完全相同


有什么想法吗?

当您单击元素时,表达式会发生变化,因此测试会“忘记”他们应该单击的内容

建议使用行动构建方法,如下所示:


伙计们,你们必须试试这个,它在Chrome、Firefox和IE中都能正常工作

您只需使用npm安装“html dnd”,这是一个链接:

安装后,您只需执行此命令

browser.execute(拖放、['#可拖放'、'#可拖放'])

例如:

var dragAndDrop = require('html-dnd').codeForSelectors;
browser.execute(dragAndDrop,['#elemendId1','#elemendId2']).pause(2000);

希望这对您的测试用例能起到很好的作用。

目前在
Nightwatch
1.5.1版,我可以使用以下示例进行拖放

示例:

“步骤1:拖放”:功能(浏览器){
browser.moveToElement('yourLocator','#startingElement',0,0);
browser.mouseButtonDown(0);
browser.moveToElement('yourLocator','#endingElement',0,0);
browser.mouseButtonUp(0);
}

您使用的是哪种操作系统?你能分享html吗?您编写的代码在Windows上运行良好,但在OSX上失败。有趣的是,我使用的是OSX,到目前为止还没有在Windows上尝试过。将在接下来的几天内尝试验证。它在Windows上也不适用于我。
mouseButtonDown()
不会触发HTML5拖放API。不幸的是,这对我不起作用(Selenium 3,ChromeDriver)–该命令似乎没有任何作用。尽管如此,谢谢你的回答。这对我来说很有效,但根据文件的要求是错误的。应该是
var dragAndDrop=require(“html dnd”)。codeForSelects
。请参阅与nightwatch一起使用的文档。这对我在BrowserStack上使用nightwatch js很有用