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 –
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
System.setProperty("webdriver.chrome.driver","D:\\Sandeep\\Soft\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://demo.guru99.com/test/drag_drop.html");
//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();
}
}
0 Comments