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 – holding the mouse button down while moving the mouse

In this section we will have a look at how we can press down the left mouse button and then move it around the page. If you are working on a canvas that tracks the mouse movements, you would be able to draw a picture with the actions API. Let's 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(); driver.get('http://www.theautomatedtester.co.uk/demo1.html') Actions builder = new Actions(driver); WebElement canvas = driver.findElement(By.id("tutorial")); Action dragAndDrop = builder.clickAndHold(canvas) .moveByOffset(-40, -60) .moveByOffset(20, 20) .moveByOffset(100, ...

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