Reputation: 104
I am trying to drag and drop an element from a list, user needs to click on the ellipses and the drag drop the element to destination. I tried with different ways but it's not working and it does not throw any error. My test case is also showing as passed with out performing drag and drop.
I want the Entrepreneur to be dragged and dropped to the location of Professor but it's not working at all.
below is the html for the same
<div class="row role"><div class="col-sm-7 role-name">Entrepreneur</div><div class="col-sm-5"><!----><span class="one-glober"><!----><!----></span><i class="fa fa-bars pull-right drag-roles"></i></div></div>
<li id="2" draggable="false" class="active" style=""><div class="row role"><div class="col-sm-7 role-name">Professor</div><div class="col-sm-5"><!----><i class="fa fa-bars pull-right drag-roles"></i></div></div></li>
i have tried below ways to do so but none of them is working.
@FindBy(xpath="//li[@id='2']//i[@class='fa fa-bars pull-right drag-roles']")
private WebElement source;
@FindBy(xpath="//li[@id='4']//i[@class='fa fa-bars pull-right drag-roles']")
private WebElement destination;
public CharacterRoleDragDropPage dragAndDrop() throws InterruptedException {
wait.until(ExpectedConditions.invisibilityOf(loader));
Actions action= new Actions(driver);
//action.dragAndDrop(source, destination).build().perform();
//action.clickAndHold(source).moveToElement(destination).release().build().perform();
source.click();
//action.clickAndHold(source).dragAndDropBy(source,0, 500).build().perform();
//action.clickAndHold(source).moveByOffset(0, 500).moveToElement(destination).build().perform();
//action.clickAndHold(source).moveToElement(destination).release(source).build().perform();
action.clickAndHold(source).dragAndDrop(source, destination).build().perform();
return this;
}
Upvotes: 0
Views: 213
Reputation: 3625
I also had trouble with drag & drop
and figured, if I used moveByOffset
method with a combination of pause
it started to work.
You can try below code:
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();
Upvotes: 1