2

I'm working on a test that performs a drag and drop.

My code currently:

WebElement element;
By mainSelector, secondarySelector;
Actions action;

action = new Actions(driver);

mainSelector = By.cssSelector("tbody.naam tr:nth-child(1) td:nth-child(1)");
secondarySelector = By.cssSelector("tbody.bedrijf tr:nth-child(1) td:nth-child(1)");

action.click(driver.findElement(mainSelector));

action.clickAndHold(driver.findElement(mainSelector))
    .moveToElement(driver.findElement(secondarySelector), 5, 5)
    .perform();
action.release(driver.findElement(secondarySelector));

action.perform();

action.dragAndDropBy(driver.findElement(mainSelector), 300, 300).perform();

action.dragAndDrop(driver.findElement(mainSelector), driver.findElement(secondarySelector)).perform();

But this does not do anything. I have added multiple performs so be sure that that is not the problem. I have added an offset because i read that this sometimes is buggy. I used firefox for testing.

Funonly
  • 818
  • 1
  • 8
  • 22
  • Kindly check : http://stackoverflow.com/questions/14210051/how-to-automate-drag-drop-functionality-using-selenium-web-driver – Helping Hands Dec 08 '14 at 09:09

1 Answers1

-1

If you want to drag mainSelector into secondarySelector, you can do something like this

Method 1

mainSelector = driver.findElement(By.cssSelector("tbody.naam tr:nth-child(1) td:nth-child(1)"));
secondarySelector = driver.findElement(By.cssSelector("tbody.bedrijf tr:nth-child(1) td:nth-child(1)"));

action = new Actions(driver)
action.dragAndDrop(mainSelector, secondarySelector).perform();

Method 2

action.clickAndHold(mainSelector).moveToElement(secondarySelector).release().build().perform();

Both method would do the task.

Hope it helps! :)

Paras
  • 3,197
  • 2
  • 20
  • 30