I am trying to drag draggable 1 to drop here box. Draggable 1 can get clicked and holding, but not be able to drag to the drop box. Any help would be appreciated.
WebDriver driver = new ChromeDriver();
driver.get("https://www.seleniumeasy.com/test/drag-and-drop-demo.html");
WebElement from = driver.findElement(By.xpath("//*[@id=\"todrag\"]/span[" + n + "]"));
WebElement to = driver.findElement(By.xpath("//div[@dropzone]"));
Actions act = new Actions(driver);
act.clickAndHold(from).moveToElement(to).release(to).build().perform();
}
Try Action Dragged and dropped method to achieve above functionality. Also your xpaths are incorrect. please refer correct xpath as below:
//span[contains(text(),'Draggable'"+ n +"')]
//div[@id='mydropzone']
Drag and drop
Actions act=new Actions(driver);
act.dragAndDrop(From, To).build().perform()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.