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 && !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
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.
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]'})");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.