Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in DevOps and Agile by (19.7k points)

How to automate drag & drop functionality using Selenium WebDriver in java?

1 Answer

0 votes
by (62.9k points)

Here is a piece of code below, which include a dragAndDrop(x,y) method of Action class, that takes two arguments x and y, x being source location and y being target location. (x,y).

 try {

         System.out.println("Drag and Drom started :");

                Thread.sleep(12000);

                Actions actions = new Actions(webdriver);

                WebElement srcElement = webdriver.findElement(By.xpath("source Xpath"));

                WebElement targetElement = webdriver.findElement(By.xpath("Target Xpath"));

                actions.dragAndDrop(srcElement, targetElement); 

                actions.build().perform();

                System.out.println("Drag and Drom complated :");

            } catch (Exception e) {

                System.out.println(e.getMessage());

                resultDetails.setFlag(true);

            }

Browse Categories

...