Action Class in Selenium: Drag and Drop operations in WebDriver

Category: Selenium WebDriver 62 0

A website has the functionality to drag and drop objects from one set of the basket to another one. So to perform such drag and drop operations in Selenium WebDriver we will make use of Action class. From now onwards we are going to use Action class for various operations in Selenium as it makes the life of an Automation tester quite convenient.

 

Stakes of the Action class in Selenium WebDriver

We can say Action class is the father of all the major web operations in Selenium WebDriver. You can imagine a life of a Selenium Automation Tester without Action class. If Action class would not be there then our test codes will have huge complexities. Then imagine chances of falling codes at runtime would be quite high. So I highly recommend you guys to take Action class on high priority. If you have good command over it then you can easily cover 40% of your Selenium operations.

 

How to perform Drag and Drop operations in Selenium?

Now we have to define our approach to perform drag and drop operations. Firstly, get web element of the source. Here source will be the element which has to be dragged. Secondly, then take web element of the drop destination. So if you have these two then you have to plan which syntax will be best suitable for you to use in your scenario.

Ω – Do you know About Robot class?

Learn Here: How to handle Robot Class in Selenium WebDriver?

 

I will suggest, use which works best for you.

Drag and Drop Operation

Syntax(s) to perform Drag and Drop operations

Syntax# 1

 

Syntax# 2

 

Syntax# 3

 

Syntax# 4

 

You can use any of the above three syntaxes to perform drag and drop operations in Selenium WebDriver.

drag and drop operation in selenium

Test Steps

  1. Open browser
  2. Hover and click mouse on source element
  3. Drop source element to destination basket

These are generalized test cases which will be always applicable for drag and drop operation, however, you can take liability to modify it further for your own convenience.

Here is the code for you:

Related Articles

Add Comment