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 – creating an Actions chain for dragging and dropping

A lot of web applications these days allow users to drag and drop what they want where they want on the page. This is really nice from a usability point of view, but from a testability point it is a nightmare!

We can get around this with actions API.

  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(); driver.get("http://www.theautomatedtester.co.uk/demo2.html"); WebElement someElement = driver.findElement(By.className("draggable")); WebElement otherElement = driver.findElement(By.className("droppable")); Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(someElement) ...

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