相信用过Selenium webdriver的相信对Actions类并不陌生。测试的时候,经常我们在做鼠标移动到某个元素的时候,需要用到Actions类中的moveToElement方法,在此简单小结一下,
1. 控制元素位移相关:
moveToElement相关
Try to move mouse over the object element:
Actions A1=new Actions(driver);
WebElement obj=driver.findElement(By.xpath("//*[@text='Family, identity']"));
A1.moveToElement(obj).build().perform();
obj.click();
2. 拖拽功能相关:
dragAndDrop相关
Try to move some element from original position to target position:
Actions A1=new Actions(driver);
WebElement original=driver.findElement(By.className("item_normal"));
WebElement target=driver.findElement(By.className("panel_leftHigh_normal"));
A1.dragAndDrop(original, target).perform();
3. Key控制相关:
KeyUp,KeyDown相关
Select all from a input field and Delete, you can do something like this:
Actions action = new Actions(driver);
action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).sendKeys(Keys.DELETE).perform();
关于Actions相关的方法小结
猜你喜欢
转载自frances657132.iteye.com/blog/2038978
今日推荐
周排行