Saturday 20 October 2012

How to move cursor in selenium.



In automation testing,you need cursor movement for displaying hidden elements.

Here is a example:

public void mouseOverOnElement(WebElement tagElement)
{
try
{
Actions builder=new Actions(driver);
Point coordinate=tagElement.getLocation();
Robot robot=new Robot();
builder.moveToElement(tagElement, 5,5).build().perform();
builder.moveByOffset(1, 1).build().perform();
robot.mouseMove(coordinate.getX()+8,coordinate.getY()+60);

}
catch(Exception e)
{
logger.info("Error message in mouseOverOnElement method-->"+e);
}
}

Using the above code you are able to move mouse cursor.

No comments:

Post a Comment