Drag and Drops in Selenium

Drag and Drops in Selenium

 

Although the IT industry has started talking about automation seriously in the recent past, software testing has been automated years before. Reduced cost, less time consumed and accuracy in the results promoted automation in software testing. As the software industry registers consistent growth, there is a huge demand for software testers who are experts in different test automation tools.

 

There are many test automation tools and among all Selenium is the number one test automation tool used most widely across the globe to test web-based applications. Selenium is easy to learn and also easy to work with. Selenium webdriver, which is included in the latest version of Selenium has many salient features which make Selenium more user-friendly. Drag and Drops of Selenium is one such feature.

 

As you are aware, some web applications, mostly those related to e-commerce have drag and drop facility and this can be automated using Selenium webdriver. In action class, there are two different methods for drag and drop automation and this article deals with those two types of drag and drop in Selenium webdriver using Java.

 

The two different methods are “Drag And Drop Method” and “Drag And Drop By Method”.

 

Drag and Drop Method in Selenium

 

In this method, Two parameters should be passed and they are

 

  1. “Source Locator”, the element which is to be dragged and dropped
  2. “Destination Locator”, the element on which the first element should be dropped.

 

Actions.dragAndDrop(Sourcelocator, Destinationlocator)

 

Drag and Drop By Method in Selenium

 

In this method, three parameters should be passed and they are

 

  1. “Source Locator”, the element which is to be dragged and dropped
  2. “X-axis pixel value” of the second element on which the first one to be dropped.
  3. “Y-axis pixel value” of the second element on which the first one to be dropped.

 

Actions.dragAndDropBy(Sourcelocator, x-axis pixel of Destinationlocator, y-axis pixel of Destinationlocator)

 

Both these methods have advantages and disadvantages depending on different scenarios and conditions. The maximum accuracy in the testing can be obtained by using the right method which is more suitable for the application. Hence, one should learn about both these methods in detail. All Selenium testing training courses will have detailed class on drag and drop in Selenium in detail.

 

Related posts

Leave a Comment