简体   繁体   中英

Drag & Drop using Selenium with Java for automation testing

I'm working on automation project work using Selenium tool. I am trying to achieve the Drag&Drop concept in Web application, having difficulty to drop the object into the Destination (Drop location). The following piece of code used to achieve this:

Actions action = new Actions(driver);
Actions actions = new Actions(driver);
WebElement Destination = driver.findElement(By.xpath("html/body/div[1]/div/div/div[4]/div/div/ul"));
action.moveToElement(element);
action.build().perform();
action.clickAndHold(element).moveToElement(Destination).release(Destination).build();
actions.perform();

I'm not supposed to use "move offset"option.

Could you please help me to resolve this issue (or) any suggestions to achieve this?

From the documentation drag-and-drop

You could do something like this:

Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.name("source")); //source
WebElement Destination = driver.findElement(By.xpath("html/body/div[1]/div/div/div[4]/div/div/ul")); //target
actions.dragAndDrop(element, Destination).perform();

What is your " element " in your code? I can imagine is the "source" element.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM