0 votes
1 view
in DevOps and Agile by (19.8k points)

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

1 Answer

0 votes
by (63.4k 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);

            }

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...