Selenium Interview : How will you perform drag and drop using WebDriver?

How will you perform drag and drop using WebDriver?

Answer: We can use Actions class. The sample code is as follows:

Actions act = new Actions(driver);

WebElement source = driver.findElement(By.xpath(“ —–”)); //source element which you want to drag

WebElement target = driver.findElement(By.xpath(“ —–”)); //target where you want to drop

act.dragAndDrop(source,target).perform();