Thursday, 26 March 2015

Drag And Drop in Selenium Webdriver

Let’s say we have a web application where we need to drag an item from one location to another location. These kinds of complex actions are not available in basic element properties. Automating rich web application is interesting, as it involves advanced user interactions. Thankfully Selenium has provided a separate “Actions” class to handle these advanced user interactions.
How it works:The action chain generator implements the Builder pattern to create a Composite Action containing a group of other actions. This should ease building actions by configuring an Actions chains generator instance and invoking its build( ) method to get the complex action.
It was really very hard for me to search for a website where I can try ‘Drag n drop’ feature of WebDriver. I was lucky to find two website. 
Example 1: In this example we will drag the Thriller folder from the left table on to the Bestsellers folder of the right side table. DragNDrop-1
Now if you carefully look at the folder, you will notice that the Thrillers folder is been moved to Bestsellers folder. The new folder structure will look like this:DragNDrop-2
Example 2: In this example there is a Checklist on the left side and there are four sub menus with the name of DragAndDrop-[1-3]. We will login to this website and then drag DragAndDrop-1 to DragAndDrop-4 of the left side sub menu.
DragNDrop-3
Please have a look on the video also and put special attention to it, as drag and drop action happened so swiftly that you might not able to notice it.

No comments:

Post a Comment