UI自动化页面有个元素需要双击,Geb了解不深,借鉴了selenium鼠标操作的方法,先把selenium的方法列举一下:
WebElement login=driver.findElement(By.className(“menuContent”));
//List集合接收前段开发,后端开发,移动开发的条目,注意用的是findElements不是findElement,多一个"s"
List elements=login.findElements(By.className(“item”));
//创建动作对象,并且指定操作的浏览器
Actions actions=new Actions(driver);
//单击操作传入参数,并且使用perform()提交,生效
//actions.click(login).perform();
//双击操作
//actions.doubleClick(login).perform();
//右击操作
//actions.contextClick(login).perform();
//actions.moveToElement().perform();
//鼠标悬停在List集合的第一个元素即"前段开发"
actions.moveToElement(elements.get(0)).perform();
//点击"前段开发"中包含的"HTML/CSS"条目
在geb中使用为:
先引入Selenium中Actions方法:
import org.openqa.selenium.interactions.Actions
使用:
class TaskInWaitIframe extends Page {
static at = { true }
static content = {
NodeNameButton { $(‘td.datagrid-cell’, text: ‘初审’) }
}
//定义方法:双击初审任务
def clickNodeNamebutton(){
waitFor {NodeNameButton}
//元素双击的方法
Actions actions = new Actions(driver)
actions.doubleClick(NodeNameButton.firstElement()).perform()
}
}
这里geb中定位的元素需要调用一下.firstElement()就转换成WebElement 类型
右击使用:contextClick()方法