How To Perform Drag And Drop Action in Selenium WebDriver?
Question
How To Perform Drag And Drop Action in Selenium WebDriver?
Answer
The Actions class has two methods that support Drag and Drop.
1.dragAndDrop(Sourcelocator, Destinationlocator)
- dragAndDropBy(Sourcelocator, x-axis pixel of Destinationlocator, y-axis pixel of Destinationlocator)
Actions.dragAndDrop(Sourcelocator, Destinationlocator)
First parameter ""Sourcelocator"" is the element which we need to drag
Second parameter ""Destinationlocator"" is the element on which we need to drop the first element
Also below method can be used
Actions.dragAndDropBy(Sourcelocator, x-axis pixel of Destinationlocator, y-axis pixel of Destinationlocator)
dragAndDropBy method we pass the 3 parameters -
First parameter ""Sourcelocator"" is the element which we need to drag
The second parameter is x-axis pixel value of the 2nd element on which we need to drop the first element.
The third parameter is y-axis pixel value of the 2nd element on which we need to drop the first element.