[Selenium]Release in dragAndDrop doesn't work after i update the version of Selenium to 2.45.0

在升级Selenium的版本之前,写了一段拖拽的代码,Drag and Drop 都好使的, 但是,将Selenium的版本升级到2.45.0之后,图标拖拽可以成功,释放不生效。

试了N多种解决方案都不管用,后来发现下面这种办法可行。

一开始在界面可以看得见的,用来进行拖拽的图标是dragable的,

在开始拖拽之后一个dropable的元素会从不可见变得可见,这个dropable的元素就是在界面可以晃动的那个元素

用代码实现拖拽并放开的操作分解之后是这样的:

1.点击并hold住dragable的元素

2.将鼠标移动到想到移到的那个container元素,dropable的元素变成可见的

3.释放dropable的元素

public void dragAndDropToElementContainner(WebDriver driver, WebElement dragableEl, WebElement dropableEl,  WebElement targetEl){
		Actions action = new Actions(driver);
		action.clickAndHold(dragableEl).build().perform();
		action.moveToElement(targetEl);
		action.release(dropableEl);
		action.build().perform();
	}
public void dragAndDropOffset(WebDriver driver,WebElement dragableEl, WebElement dropableEl, int offsetX, int offsetY){
		Actions action = new Actions(driver);
		action.clickAndHold(dragableEl).build().perform();
		action.moveByOffset(offsetX, offsetY);
		action.release(dropableEl);
		action.build().perform();
	}
原文地址:https://www.cnblogs.com/MasterMonkInTemple/p/4535009.html