使用Protractor.net c#拖放功能停止工作的可能原因是什么?
使用http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/advanced来测试此功能。但是没有为我工作。
以下是我尝试的示例代码:
Wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(&#34; // h3 [。=&#39; Container(允许效果:全部)&#39;]&#34;))); < / p>
var elem = NgDriver.FindElement(By.XPath(&#34; // h3 [。=&#39;容器(允许的效果:全部)&#39;]&#34;));
IWebElement parentElement = elem.FindElement(By.XPath(&#34; ..&#34;));
IWebElement mov = parentElement.FindElement(NgBy.Repeater(&#34; container.items中的项目&#34;));
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()函数进行尝试。
任何帮助将不胜感激。
答案 0 :(得分:0)
创建一个名为&#34; drop.js&#34;的Javscript文件。并设置以下内容。
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
是用于拖动和滴水的控件。这些控件应包含&#34; draggable&#34;等属性。或&#34;可丢弃&#34;在他们的HTML标签中。