0

拖放功能停止使用 Protractor.net c# 为我工作的可能原因是什么?

使用http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/advanced来测试这个功能。但对我没有用。

这是我尝试的示例代码:

Wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//h3[.='Container (允许的效果:全部)']")));

var elem = NgDriver.FindElement(By.XPath("//h3[.='Container (effects allowed: all)']"));

IWebElement parentElement = elem.FindElement(By.XPath(".."));

IWebElement mov = parentElement.FindElement(NgBy.Repeater("item in container.items"));

      Wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//h3[.='Container (effects allowed: move)']")));
        var drropElem = NgDriver.FindElement(By.XPath("//h3[.='Container (effects allowed: move)']"));
        IWebElement parentElement2 = drropElem.FindElement(By.XPath(".."));


        IWebElement mov2 = parentElement2.FindElement(NgBy.Repeater("item in container.items"));
Actions builder = new Actions(Driver);
        Actions action = builder.ClickAndHold(mov);
        builder.Build();
        action.Perform();

        builder = new Actions(Driver);
        action = builder.MoveToElement(mov2);
        builder.Release(mov2);
        builder.Build();
        action.Perform();

还尝试了 Action 中的 DragAndDrop() 函数。

任何帮助将不胜感激。

4

1 回答 1

0

创建一个名为“drop.js”的 Javascript 文件并设置以下内容。

function e(e,t,n,i){var r=a.createEvent("DragEvent");r.initMouseEvent(t,!0,!0,o,0,0,0,c,g,!1,!1,!1,!1,0,null),Object.defineProperty(r,"dataTransfer",{get:function(){return d}}),e.dispatchEvent(r),o.setTimeout(i,n)}var t=arguments[0],n=arguments[1],i=arguments[2]||0,r=arguments[3]||0;if(!t.draggable)throw new Error("Source element is not draggable.");var a=t.ownerDocument,o=a.defaultView,l=t.getBoundingClientRect(),u=n?n.getBoundingClientRect():l,c=l.left+(l.width>>1),g=l.top+(l.height>>1),s=u.left+(u.width>>1)+i,f=u.top+(u.height>>1)+r,d=Object.create(Object.prototype,{_items:{value:{}},effectAllowed:{value:"all",writable:!0},dropEffect:{value:"move",writable:!0},files:{get:function(){return this._items.Files}},types:{get:function(){return Object.keys(this._items)}},setData:{value:function(e,t){this._items[e]=t}},getData:{value:function(e){return this._items[e]}},clearData:{value:function(e){delete this._items[e]}},setDragImage:{value:function(e){}}});if(n=a.elementFromPoint(s,f),!n)throw new Error("The target element is not interactable and need to be scrolled into the view.");u=n.getBoundingClientRect(),e(t,"dragstart",101,function(){var i=n.getBoundingClientRect();c=i.left+s-u.left,g=i.top+f-u.top,e(n,"dragenter",1,function(){e(n,"dragover",101,function(){n=a.elementFromPoint(c,g),e(n,"drop",1,function(){e(t,"dragend",1,callback)})})})})

在你的代码中

     string jsScript = Path.Combine(currentDirectory, "JavaScript", "drop.js");
        if (File.Exists(jsScript))
        {
            string dragAndDropScript = File.ReadAllText(jsScript);
            IJavaScriptExecutor jse = (IJavaScriptExecutor)NgDriver;
            jse.ExecuteScript(dragAndDropScript, dragFrom, dragTo);
        }

drafFrom并且dragTo是用于拖动和滴落的控件。这些控件应在其 HTML 标记中包含“可拖动”或“可放置”等属性。

于 2018-02-16T08:42:40.193 回答