[英]Drag & Drop using Selenium with Java for automation testing
I'm working on automation project work using Selenium tool. 我正在使用Selenium工具进行自动化项目工作。 I am trying to achieve the Drag&Drop concept in Web application, having difficulty to drop the object into the Destination (Drop location).
我试图在Web应用程序中实现“拖放”概念,但是很难将对象拖放到“目标”(“拖放”位置)中。 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.
我可以想象是“源”元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.