Skip to content

Drag N Drop Java Example - no working example #27

@timrsfo

Description

@timrsfo

I can't get Drag And Drop Java working. I've searched for hours and only find errors without solutions for MoveToElement and DragAndDrop and/or clickAndHold-MoveToElement-Release.

The following are some snippets of what I've tried:

`
public static final By COLUMN_A = By.id("column-a");
public static final By COLUMN_B = By.id("column-b");

@Test
public void dragAtoBTest() {
    Actions action = new Actions(driver);
    log.info("drag column-a to column-b position");
    WebElement weA = driver.findElement(DragNDropPage.COLUMN_A);
    WebElement weB = driver.findElement(DragNDropPage.COLUMN_B);
    action.dragAndDrop(weA, weB).build().perform();

    log.info("wait for opacity to change back to 1 from 0.4");
    wait.until(ExpectedConditions.attributeToBe(weA, "opacity", "1"));
    assertThat(weA.findElement(page.columnHeader).getText(),  containsString("B"));
}

@Test
public void clickHoldMoveReleaseAtoBTest() {
    Actions action = new Actions(driver);
    log.info("click and hold column-a");
    
    WebElement weA = driver.findElement(DragNDropPage.COLUMN_A);
    WebElement weB = driver.findElement(DragNDropPage.COLUMN_B);
    
    action.clickAndHold(weA)
    .moveByOffset(-1, -1) // To fix issue with drag and drop in Chrome V61.0.3163.79
    .moveToElement(weB, 
            weB.getLocation().getX()+weB.getSize().getWidth()/2, 
            weB.getLocation().getY()+weB.getSize().getHeight()/2)
    .release(weB)
    .build()
    .perform();
    
    
    
//       action.clickAndHold(weA).build().perform();
//        log.info("moveToElement column-b");
//        action.moveToElement(weB).build().perform();

   //        log.info("release on column-b");
   //        action.release().build().perform();
    
    
    
    log.info("wait for opacity to change back to 1 from 0.4");
    wait.until(ExpectedConditions.attributeToBe(weA, "opacity", "1"));
    assertThat(weA.findElement(page.columnHeader).getText(),  containsString("B"));`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions