- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 do drag and drop action in Selenium?
We can perform drag and drop action in Selenium with the help of Actions class. In order to perform the drag and drop movement we will use dragAndDrop (source, target) method. Finally use build().perform() to execute all the steps.
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class DrgAndDrp{ 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/draggable/v"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); driver.switchTo().frame(0); WebElement source= driver.findElement(By.id("draggable")); WebElement target= driver.findElement(By.id("droppable")); // dragAndDrop() method for dragging the element from source to //destination Actions a = new Actions(driver); Thread.sleep(5000); a.dragAndDrop(source, target).build().perform(); Thread.sleep(5000); driver.quit(); } }
- Related Articles
- How to simulate HTML5 Drag and Drop in Selenium Webdriver?
- How to perform drag and drop operation in Selenium with python?
- How to automate drag & drop functionality using Selenium WebDriver Java?
- How to use drag and drop in Android?
- How to use drag and drop in HTML5?
- How to perform drag and drop actions in WebdriverIO?
- HTML5 drag and drop will not drop
- How to stop dragend's default behavior in drag and drop?
- How to Add Drag and Drop in React using React Beautiful DnD
- How to work with JavaScript Drag and drop for touch devices?
- Drag and Drop a File feature in React JS
- Cross-browser drag-and-drop HTML file upload?
- The dragLeave event fires before drop for HTML5 drag and drop events
- Full page drag and drop files website with HTML
- HTML5 Canvas and select / drag-and-drop features in a JS library?

Advertisements