拖放功能停止使用protractor.net c#?
的可能原因是什么原因使用http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/advanced来测试此功能。但没有为我工作。
这是我尝试过的示例代码:
wait.until(ExpectConditions.elementisvisible(by.xpath)
var elem = ngdriver.findelement(by.xpath("//h3 [。='容器(允许效果允许:all)']"));
iwebelement parentlement = elem.findelement(by.xpath(" .."));
iwebelement mov = parentelement.findelement(ngby.repeater(" inter in Container.items in intem in container in.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();
在thee Action中还尝试使用draganddrop()函数。
任何帮助将不胜感激。
创建一个名为" drop.js"的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
是用于拖动和滴落的控件。这些控件应包含其HTML标签中的"可拖动"或"可删除"的属性。