首页 > 解决方案 > 在硒中拖放时元素会重叠

问题描述

我在拖放 selenium 时遇到问题。实际上我希望将元素放置在不同的位置,但在我的情况下,所有元素在放置时都会重叠。我使用偏移量使用了所有可能的代码集,但最终得到了相同的场景。

Actions actions = new Actions(driver);

Actions action = new Actions(driver);

//1st method            
            actions.clickAndHold(circle).moveByOffset(555,575).build().perform();           
action.release(destination).build().perform();
actions.clickAndHold(rect).moveByOffset(726,598).build().perform();
action.release(destination).build().perform();*/


//2nd method

actions.clickAndHold(circle).moveToElement(destination,331,151).build().perform();
action.release(destination).build().perform();
            actions.clickAndHold(rect).moveToElement(destination,584,137).build().perform(); action.release(destination).build().perform();     actions.clickAndHold(src).moveToElement(destination,82,367).build().perform();
action.release(destination).build().perform();

//3rd method

actions.dragAndDropBy(circle, 331, 151);
actions.dragAndDropBy(rect, 584, 137);
actions.build().perform();

//4th method

actions.dragAndDrop(src, destination); 
actions.dragAndDrop(rect, destination);

actions.dragAndDrop(圆圈,目的地);action.build().perform();

标签: javaselenium

解决方案


你有没有试过这个方法:

(new Actions(Driver)).DragAndDropToOffset(element, xoffset, yoffset).Perform();

推荐阅读