# WebDriver 里的拖拽实现

I am having intermittent issues when doing drag & drop operations with ChromeDriver. Here is an excerpt from the code that causes the problem:

WebElement resizeHandle = wd.findElement(By.xpath("//section[@id='fullscreenView']//div[contains(@class,'resizeHandle')]"));
Actions builder = new Actions(wd);
Action dragAllTheWayUp = builder.dragAndDropBy(resizeHandle, 0, -200).build();
dragAllTheWayUp.perform();

Unfotunately I can not provide a real test case as the tested web application is not publicly available.
The idea of the code is to drag a div (which works as a resize handle in the application) up in the browser. This works perfectly with IE and with Firefox, but in Chrome around 1 of 4 times the div seems to be dragged down (i.e. as if positive offset was given in the dragAndDropBy() method)

hello,
dragAndDropTo() doesn't work for me in the chrome driver very well. if it tries to drag to somewhere outside of the current viewing window it gives me funny results, like dragging in an incorrect direction.
if you can't fix it you might try building the steps of the drag and drop yourself

like such

Action dragAllTheWayUp = builder.MoveToElement(resizeHandle)
.ClickAndHold()
.MoveByOffset(x, y)
.Release()
.Build();

dragAllTheWayUp.perform();

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客