How do Perform Drag and Drop using WebDriver?


In this post, we will discuss drag and drop using WebDriver. For this purpose, we need to use Action class.
Under Actions, class various method is defined to serve various actions that are needed to be performed. One such method is dragAndDrop().
Below is the sample code:


Actions action = new Actions(driver);

WebElement source = driver.findElement(By.xpath(“myXpath”));
//source element which you want to drag

WebElement target = driver.findElement(By.xpath(“myXpath”));
//target where you want to drop

action .dragAndDrop(source,target).perform();

Facebook Comments


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.