Drag And Drop Using Actions Class In Selenium WebDriver

How To Drag and Drop Action in Selenium webdriver 

dragAndDrop(WebElement src,WebElement dest)

By Using Drag and Drop Method We Achieve the requirement
First Find The Xpath Of Both Source And Destination then Follow the Step

Selenium Code For Drag and Drop
package automationtesting;

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;

public class DragDrop {

       public static void main(String[] args) {
              // TODO Auto-generated method stub
              WebDriver driver= new ChromeDriver();
                     //Element which needs to drag.          
                     WebElement From=driver.findElement(By.xpath("//*[@id=\"fourth\"]/a"));    
                //Element on which need to drop.             
                WebElement To=driver.findElement(By.xpath("//*[@id=\"amt8\"]/li"));                                 
                //Using Action class for drag and drop.             
                Actions act=new Actions(driver);                                 

                    //Dragged and dropped.            
                act.dragAndDrop(From, To).build().perform();        


Post a Comment