您的位置:首页 > 运维架构

[Selenium]计算坐标进行拖拽,重写dragAndDropOffset

2015-05-29 09:18 113 查看
//@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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: