how to drag element using selenium

by (14 points)
0 votes
I have a scenario, where I need to drag element. how do I implement this?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

2 Answers

answered by
selected by
0 votes
Best answer

You can use below code:


Actions moveSlider = new Actions(driver);
Action action = moveSlider.dragAndDropBy(driver.findElement("Selemnt selector"), xAxis yAxis).build();

answered by (11 points)
0 votes
-> go to url -> create action class -> web element source -> web element destination -> perform action (click and hold source -> move to destination element -> release the element)


public class DragAndDrop
public static void main (String []arg) throws Exception
        String url = "https://softwaretestingboard.com/q2a/1/how-to-drag-element-using-selenium#axzz5eTh5jQe0";
        String un ="Admin";
        String pw = "[email protected]";
        System.setProperty("webdriver.gecko.driver", "D:\\Soft\\geckodriver.exe");
        WebDriver driver =new FirefoxDriver();
        Actions ActionDrageAndDrop = new Actions (driver);
        WebElement Source = driver.findElement(By.xpath("/html/body/div[1]/div[2]/ul/a"));
        WebElement Destination = driver.findElement(By.xpath("/html/body/div[1]/div[2]/ul/a"));
        /* also try with direct method dragAndDrop
        ActionDrageAndDrop.dragAndDrop(Source, Destination).build().perform();