O'Reilly logo

Selenium 2 Testing Tools Beginner's Guide by David Burns

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – moving an element with a drag-and-drop by offset

There are times where we need to only move an image by a certain amount. A good example of this would be if you are working in a WYSIWYG editor and you wanted to just move an image to somewhere else but did not want to drop it on another element, you will be using dragAndDropBy(WebElement, x, y);.

Let us see this in action.

  1. Open up inteliij and create a new Selenium WebDriver project.
  2. Create a new class and a new test with the following code:
    WebDriver driver = new FirefoxDriver(); co.uk/demo2.html"); WebElement drag = driver.findElement(By.className("draggable")); Actions builder = new Actions(driver); Action dragAndDrop = builder.dragAndDropBy(drag, 10, 20) .build(); dragAndDrop.perform(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required