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.,

5 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. It was very nice blog to learn about SAP BASIS. Thanks for sharing.SAP basis

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

    ReplyDelete