简体   繁体   English

IE11无法自动拖放:Selenium WebDriver

[英]Unable to Automate Drag and Drop for IE11 : Selenium WebDriver

I am trying to automate drag and drop functionality in IE11 using Selenium Web Driver in Java. 我正在尝试使用Java中的Selenium Web Driver自动执行IE11中的拖放功能。 I am somehow able to achieve it on Chrome, but it's not happening in IE. 我能够以某种方式在Chrome上实现它,但在IE中却没有发生。

Before further explanation here is how I'm dragging and dropping: 在进一步解释之前,这里是我如何拖放:

Actions builder = new Actions(driver);
builder.clickAndHold(sourceElement)
 .moveToElement(targetElement)
 .release(targetElement)
 .build().perform();

In IE: Instead of dragging and dropping it selects all the text from source to destination element. 在IE中:而不是拖放,而是选择从源元素到目标元素的所有文本。 I thought this might be because it's pickup up the wrong element and tried the operation with some relevant parent and child elements but didn't work. 我认为这可能是因为它拾取了错误的元素,并尝试了一些相关的父元素和子元素的操作,但是没有用。

In Chrome: Works damn smooth. 在Chrome浏览器中:运作非常流畅。

In Firefox: Just performs click on holds and while dragging throws, element no longer attached to DOM exception . 在Firefox中:只需单击保持并拖动,而element no longer attached to DOM exception This might be because, I am dragging a row from a grid (kendo grid) and since dragging a row from a grid is not possible our devs have implemented it in such a way that when you drag a row a new dynamic element is created which moves along. 这可能是因为,我要从网格(剑道网格)中拖出一行,并且由于不可能从网格中拖出一行,因此我们的开发人员已经实现了这种方式,当您拖动行时,会创建一个新的动态元素,前进。

Just to add on more details: 只是添加更多细节:

  1. I have already tried dragAndDrop() and other Javacript options. 我已经尝试过dragAndDrop()和其他Javacript选项。
  2. I'm using the latest version of selenium and updated IE. 我正在使用最新版本的Selenium和更新的IE。
  3. Our grid uses HTML5 components and I've discovered that there are few issues already there (not sure about what all issues though), but still since my scenario was working in one browser I hope this is not one of those issues. 我们的网格使用HTML5组件,我发现那里已经有几个问题了(尽管不确定所有问题是什么),但是由于我的场景是在一个浏览器中工作的,所以我希望这不是这些问题之一。
  4. I have made it possible somehow using Robot class but it is too unreliable and behaves weird, I would prefer giving up than using it. 我已经通过某种方式使使用Robot类成为可能,但是它太不可靠且行为怪异,与使用它相比,我宁愿放弃。

Any help will be appreciated! 任何帮助将不胜感激!

One solution if it's an HTML5 drag and drop is to simulate it with some javascript. 如果是HTML5拖放,一种解决方案是使用一些javascript模拟它。 Here is a working example that drops an item to a bin: 这是一个将项目拖放到垃圾箱的工作示例:

final String JS_DnD =
"var src=arguments[0],tgt=arguments[1];var dataTransfer={dropEffe" +
"ct:'',effectAllowed:'all',files:[],items:{},types:[],setData:fun" +
"ction(format,data){this.items[format]=data;this.types.append(for" +
"mat);},getData:function(format){return this.items[format];},clea" +
"rData:function(format){}};var emit=function(event,target){var ev" +
"t=document.createEvent('Event');evt.initEvent(event,true,false);" +
"evt.dataTransfer=dataTransfer;target.dispatchEvent(evt);};emit('" +
"dragstart',src);emit('dragenter',tgt);emit('dragover',tgt);emit(" +
"'drop',tgt);emit('dragend',src);";

WebDriver driver = new InternetExplorerDriver();
driver.get("http://html5demos.com/drag");

WebElement ele_source = driver.findElement(By.id("two"));
WebElement ele_target = driver.findElement(By.id("bin"));

// drag and drop item two into the bin
((JavascriptExecutor)driver).executeScript(JS_DnD, ele_source, ele_target);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM