Tuesday, 31 December 2013

Handling Drag & Drop for HTML5 | Robot [Webdriver]

Usual drag & drop doesn't work on pages built with HTML5. Here, I've used Robot for controlling the Mouse Actions to work with HTML5 websites.

Snippet

@Test
public void dragAndDrop() throws AWTException, InterruptedException {

driver.get("http://demo.kaazing.com/forex/");
Actions builder = new Actions(driver);
WebElement sourceElement = driver.findElement(By.xpath("(//li[@name='dragSource'])[13]"));
Action drag = builder.clickAndHold(sourceElement).build();
drag.perform();
    
WebElement targetElement = driver.findElement(By.xpath("//section[@id='section1']/div[2]"));
Point coordinates = targetElement.getLocation();
Robot robot = new Robot(); //Robot for controlling mouse actions
robot.mouseMove(coordinates.getX(),coordinates.getY()+120);
Thread.sleep(5000);
}

Note| Java Robot can also be used for various actions like locating tooltips, etc.,

7 comments:

  1. FYI, you can do HTML5-based drag & drop without having to use Robot or anything like Sikuli, AutoIt.

    There's a javascript/jQuery-based solution given in the bug tracker for HTML5 drag & drop support in Selenium:

    https://code.google.com/p/selenium/issues/detail?id=3604

    that is a lot more scalable than using Robot if you were to run tests over Grid and SauceLabs.

    ReplyDelete
  2. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium

    ReplyDelete
  3. Thanks for the great information in your blog Selenium Training in Chennai

    ReplyDelete
  4. It was very nice blog to learn about SAP BASIS. Thanks for sharing.SAP basis

    ReplyDelete
  5. I advise that you pick the most recommended Forex broker - AvaTrade.

    ReplyDelete
  6. http://letusnotifyyou.com/appium-selenium-configuration-latest-ios-version-10-3-2/

    ReplyDelete