I am facing issue in drag and drop in html5 with selenium java

隐身守侯 提交于 2019-12-13 09:47:58

问题


I am newbie to java and selenium. i am facing issue in dragAndDrop in HTML5. can you please help me?

Code i am using is :

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>

回答1:


Try my version of drag and drop via Actions interface

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();

In my application, When I clickAndHold the destination element changes. That's why I added pauses.




回答2:


This is an old problem not fixed yet with Selenium and Html5; but there is a solution that you can find here (credit to rcorreia): https://gist.github.com/rcorreia/2362544#file-drag_and_drop_helper-js

Just execute that js file js.ExecuteScript(jsfile + "$('#[sourceElement]').simulateDragDrop({dropTarget: '#[targetElement]'})");



来源:https://stackoverflow.com/questions/48840823/i-am-facing-issue-in-drag-and-drop-in-html5-with-selenium-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!