码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-29 09:44:41      阅读:809      评论:0      收藏:0      [点我收藏+]

标签:

//@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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!