标签:
//@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); }
[Selenium]计算坐标进行拖拽,重写dragAndDropOffset
标签:
原文地址:http://www.cnblogs.com/MasterMonkInTemple/p/4537699.html