【问题标题】:Unable to drag Element/Item into the Drop Area/Container无法将元素/项目拖到放置区域/容器中
【发布时间】:2020-09-18 13:12:15
【问题描述】:

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

使用的技术/软件

  • IDE:Eclipse
  • 测试框架:Selenium
  • 语言:Java
  • 浏览器:Microsoft Edge - 版本 85.0.564.51

问题

  • 我无法将给定的元素/项目拖到放置区域/容器中(参见图片)
  • 我还使用了不同的 Xpath/选择器,即 By-CSS、By-Xpath 或 By-Class
  • 似乎元素/项目被选中并移动了一个或两个像素,之后元素/项目冻结并且没有被拖动到下面的放置区域/容器

我的尝试

  • 所以我尝试了不同的拖放功能,如下所示:-

      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();
    
  • 我也尝试过使用“dragAndDrop 而不是 clickAndHold”

       `action.dragAndDrop(sourceLocator, targetLocator).build().perform();`
    

就像我之前说的,项目/元素被选中 -> 移动一两个像素然后它在容器上方冻结(容器根据功能从下方弹出)

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

【问题讨论】:

  • 请发布您尝试自动化的网站

标签: java selenium drag-and-drop


【解决方案1】:

你应该尝试通过 JavaScript 来完成,使用 selenium 中的 JavaExecutor 类执行本文中的脚本,它可以为你工作

Why drag and drop is not working in Selenium Webdriver?

【讨论】:

  • 谢谢!我正在寻找的答案在您上面写的链接中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-12
  • 2022-09-24
  • 1970-01-01
  • 2013-11-16
  • 2016-03-27
  • 1970-01-01
相关资源
最近更新 更多