英文:
Unable to drag Element/Item into the Drop Area/Container
问题
无法将元素/项目拖放到放置区/容器中
使用的技术/软件:
- IDE:Eclipse
- 测试框架:Selenium
- 编程语言:Java
- 浏览器:Microsoft Edge - 版本 85.0.564.51
问题:
- 我无法将给定的元素/项目拖放到放置区/容器中(请参见图像)
- 我尝试过不同的 Xpath/选择器,如 By-CSS、By-Xpath 或 By-Class
- 元素/项目似乎被选中并移动了一两个像素,之后元素/项目就会冻结,无法被拖放到下面的放置区/容器中
我的尝试:
- 所以我尝试了不同的拖放函数,如下面的函数:
Actions action = new Actions(drv);
// 源元素
WebElement sourceLocator = drv.findElement(By.className(Item));
// 目标元素
WebElement targetLocator = drv.findElement(By.cssSelector(DropArea));
// 点击 -> 持续按住 -> 拖动 -> 放下
action.clickAndHold(sourceLocator).moveToElement(targetLocator)
.release()
.build()
.perform();
- 我还尝试了使用
dragAndDrop
替代clickAndHold
:
action.dragAndDrop(sourceLocator, targetLocator).build().perform();
正如我之前所说,元素/项目被选中 -> 移动了一两个像素,然后就会在容器的正上方冻结(根据功能,容器从下方弹出)
绿框是要拖放的项目/元素 - 红框是项目/元素应该放置的区域
英文:
Unable to drag Element/Item into the Drop Area/Container
Tech/Softwares used:
- IDE: Eclipse
- Framework for testing: Selenium
- Language: Java
- Browser: Microsoft Edge - Version 85.0.564.51
Issue:
- I'm unable to drag the given Element/Item into the Drop Area/Container (See Images)
- I've also used different Xpaths/Selectors i.e. By-CSS,By-Xpath or By-Class
- It seems that the Element/Item is selected and moved a pixel or two after which the Element/Item freezes and is not dragged to the Drop Area/Container below
My Attempt:
-
So i've tried different drag and drop functions such as the ones below:-
Actions action = new Actions(drv); //Source WebElement sourceLocator = drv.findElement(By.className(Item)); //Destination WebElement targetLocator = drv.findElement(By.cssSelector(DropArea)); //Click -> Hold -> Drag -> Drop action.clickAndHold(sourceLocator).moveToElement(targetLocator) .release() .build() .perform();
-
I've also tried using 'dragAndDrop instead of clickAndHold'
`action.dragAndDrop(sourceLocator, targetLocator).build().perform();`
Like I said earlier, The item/element is selected -> Moves a pixel or two then it freezes just above the container (The container pops-up from below as per functionality)
As you can see, the item/element is stuck/frozen right above the drop area
Outcome that is expected - Element has been dragged and dropped (Done manually) in the picture
答案1
得分: 0
你应该尝试使用JavaScript来完成这个任务,使用selenium中的JavaExecutor类来执行这篇帖子中的脚本,可能会对你有用。
https://stackoverflow.com/questions/39436870/why-drag-and-drop-is-not-working-in-selenium-webdriver
英文:
You should try to do it by JavaScript, use the JavaExecutor class from selenium execute the scripts that are in this post, it could work for you
https://stackoverflow.com/questions/39436870/why-drag-and-drop-is-not-working-in-selenium-webdriver
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论