我是java和selenium的新手。我在HTML5中遇到dragAndDrop
的问题。你能帮我么?
我正在使用的代码是:
public static void draganddrop(WebDriver driver ,WebElement Source, WebElement Destination)
{
Actions action = new Actions(driver);
action.dragAndDrop(Source, Destination).build().perform();
}
<li data-ng-repeat="item in questionType" id="divDrag0" class="ng-scope">
<!-- ngIf: !isSurveyStarted || (isSurveyStarted && !isSurveyLock) -->
<a data-ng-if="!isSurveyStarted || (isSurveyStarted && !isSurveyLock)" href="javascript:void(0)" draggable="true" id="1" class="ng-binding ng-scope">Single Choice </a>
<!-- end ngIf: !isSurveyStarted || (isSurveyStarted && !isSurveyLock) -->
<!-- ngIf: isSurveyStarted && isSurveyLock --> </li>
这是Selenium和Html5尚未解决的老问题;但有一个解决方案,你可以在这里找到(信贷rcorreia):https://gist.github.com/rcorreia/2362544#file-drag_and_drop_helper-js
只需执行js文件js.ExecuteScript(jsfile + "$('#[sourceElement]').simulateDragDrop({dropTarget: '#[targetElement]'})");
通过drag and drop
界面试用我的Actions
版本
new Actions(driver)
.moveToElement(source)
.pause(Duration.ofSeconds(1))
.clickAndHold(source)
.pause(Duration.ofSeconds(1))
.moveByOffset(1, 0)
.moveToElement(destination)
.moveByOffset(1, 0)
.pause(Duration.ofSeconds(1))
.release().perform();
在我的应用程序中,当我clickAndHold
目标元素发生变化时。这就是我添加暂停的原因。