我正在使用selenium java在html5中拖放问题

问题描述 投票:-3回答:2

我是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 &amp;&amp; !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>
java html5 selenium selenium-webdriver drag-and-drop
2个回答
1
投票

这是Selenium和Html5尚未解决的老问题;但有一个解决方案,你可以在这里找到(信贷rcorreia):https://gist.github.com/rcorreia/2362544#file-drag_and_drop_helper-js

只需执行js文件js.ExecuteScript(jsfile + "$('#[sourceElement]').simulateDragDrop({dropTarget: '#[targetElement]'})");


0
投票

通过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目标元素发生变化时。这就是我添加暂停的原因。

© www.soinside.com 2019 - 2024. All rights reserved.