Wednesday 25 May 2022

Selenium Drag and Drop Java Code Example | Mouse Actions in Selenium Webdriver

                   In this post, we will see Selenium Drag and Drop Java Code Example | Mouse Actions in Selenium Webdriver 


Program Code

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.Actions;


public class DragDrop {


public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver_win32\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://jqueryui.com/droppable/");

driver.manage().window().maximize();

Actions a=new Actions(driver);

WebElement w=driver.findElement(By.xpath("//iframe[@class='demo-frame']"));

driver.switchTo().frame(w);

a.dragAndDrop(driver.findElement(By.xpath("//div[@id='draggable']")), driver.findElement(By.xpath("//div[@id='droppable']"))).build().perform();


}


}  


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=e29hYoX5D6g

No comments:

Post a Comment