//@author jzhang6 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(); }
//@author jzhang6 public void dragWidget(String widgetName){ WebElement widgetIconEl=page.getWidgetIconInDockMenu(widgetName); ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", widgetIconEl); WebElement workspaceEl=page.getWorkSpace(); Point initialPositon = widgetIconEl.getLocation(); Point targetPositon = workspaceEl.getLocation(); int offsetX = (targetPositon.getX() - initialPositon.getX())/2; int offsetY = (targetPositon.getY() - initialPositon.getY())/2; System.out.println("Drag widget to : ("+offsetX+","+offsetY+")"); WebElement dropableEl=page.getDropableIconInWorkspace(); this.dragAndDropOffset(driver,widgetIconEl,dropableEl,offsetX, offsetY); SeleniumUtil.waitUntilAllAjaxRequestCompletes(driver); this.waitForLoadingDoneInNewWebPage(driver); }