- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to automate drag & drop functionality using Selenium WebDriver Java?
The drag and drop action is done with the help of a mouse. It happens when we drag and then place an element from one place to another. This is a common scenario when we try to move a file from one folder to another by simply drag and drop action.
Selenium uses the Actions class to perform the drag drop action. The dragAndDrop(source, destination) is a method under Actions class to do drag and drop operation. The method will first do a left click on the element, then continue the click to hold the source element. Next it shall move to the destination location and release the mouse.
Our aim to drag and drop the first box to the second box.
Example
Code Implementation.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.interactions.Actions; public class DragDrop{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://jqueryui.com/droppable/"; driver.get(url); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.switchTo().frame(0); // identify source and target element WebElement s=driver.findElement(By.("draggable")); WebElement t=driver.findElement(By.("droppable")); /Actions class with dragAndDrop() Actions act = new Actions(driver); act.dragAndDrop(s, t).build().perform(); driver.quit(); } }
Output
- Related Articles
- How to simulate HTML5 Drag and Drop in Selenium Webdriver?
- How to automate gmail login process using selenium webdriver in java?
- How to automate Calendar using Selenium WebDriver for Testing?
- How to do drag and drop action in Selenium?
- How to perform drag and drop operation in Selenium with python?
- How to specify "ENTER" button functionality in Selenium WebDriver code?
- How to automate instagram login page using java in selenium?
- How to select checkboxes using selenium java webdriver?
- How to use drag and drop in HTML5?
- How to use drag and drop in Android?
- HTML5 drag and drop will not drop
- How to Add Drag and Drop in React using React Beautiful DnD
- How to handle frame in Selenium WebDriver using java?
- How to scroll down using Selenium WebDriver with Java?
- How to use clickandwait in Selenium Webdriver using Java?

Advertisements