简体   繁体   English

我在使用 selenium java 在 html5 中拖放时遇到问题

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

I am newbie to java and selenium.我是 java 和 selenium 的新手。 i am facing issue in dragAndDrop in HTML5.我在 HTML5 中的dragAndDrop中遇到问题。 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>

Try my version of drag and drop via Actions interface通过Actions界面尝试我的drag and drop版本

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.在我的应用程序中,当我clickAndHold ,目标元素会发生变化。 That's why I added pauses.这就是我添加停顿的原因。

This is an old problem not fixed yet with Selenium and Html5;这是 Selenium 和 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但是你可以在这里找到一个解决方案(归功于 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]'})");只需执行该 js 文件js.ExecuteScript(jsfile + "$('#[sourceElement]').simulateDragDrop({dropTarget: '#[targetElement]'})");

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

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