无法将元素/项拖动到放置区域/容器中。

huangapple go评论82阅读模式
英文:

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)

Green box is the item/element to be dragged and droped - Red box is the area where the item/element should be droped

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

huangapple
  • 本文由 发表于 2020年9月18日 21:12:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63956443.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定