[英]Unable to drag and drop using Java + Selenium WebDriver
以下是源元素的HTML:
<li draggable-effect-allowed="copy" draggable-data="business.domain.view.RecordViewComponentType" draggable="view-designer-drop-zone-content" class="list-group-item ng-scope ng-binding" ng-dblclick="insertComponentType(component)" ng-repeat="component in componentTypes" draggable="true">Record</li>
以下是目标元素的HTML:
<div droppable-on-drop="onDropComponent($event, $draggableEl, $droppableEl)" droppable="view-designer-drop-zone-content" class="layoutSection ContentAreaLayoutSection" id="CONTENT"></div>
因此,我已经:
source = driver.findElement(By.xpath("//li[text()='Record']"));
target = driver.findElement(By.ID("CONTENT"));
Actions action = new Actions(driver);
为了实现拖放,我尝试使用以下API,但没有运气:
1. action.dragAndDrop(source, target).build().perform();
2. action.clickAndHold(source).moveToElement(target).release(target).build().perform();
3. action.moveToElement(source).clickAndHold(source).moveToElement(target).release(target).build().perform();
4. action.moveToElement(source).clickAndHold().moveToElement(target).release().build().perform();
5. action.clickAndHold(source).moveToElement(target).build().perform();
Thread.sleep(3000);
action.release(target).build().perform();
我也尝试过moveToElement(target, x-offset, y-offset)
仍然不起作用。
当我尝试以上所有操作时,它没有引发任何错误,并且下一个代码开始执行,并且在视觉上,我可以看到源元素已拖动,但是看起来当它移到目标元素时,它没有掉到目标元素上,仍然没有错误。抛出。
实际上,如果Selenium WebDriver和浏览器版本兼容性存在问题,我期望这里出现一些错误。
如果有人知道解决方案或解决方法,请回答。
以下代码对我有用,请尝试以下操作:
Actions act = new Actions(driver);
WebElement srcElement = driver.findElement(By
.id(locator));
Thread.sleep(3000);
WebElement targetElement =driver.findElement(By
.id(locator));
Thread.sleep(3000);
act.dragAndDrop(srcElement, targetElement);
Thread.sleep(3000);
act.build().perform();
Thread.sleep(3000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.