ExecuteAutomation

Mouse hover and click in Selenium

In this post we will discuss one of the common yet easiest feature called mouse hovering in Selenium. There are many situations where we might need to hover a to control in applications UI and the UI will bring the interactive options or menu or window on-the-fly (using JQuery or Javascript). Then we may need to click on the control and perform some other operation used for automation testing. For doing these operations, Selenium has a special package called org.openqa.selenium.interactions which has a class called Actions, which has lot of special classes to perform operation such as hover as discussed in the last post of drag and drop. We can perform the mouse hover and click in our demo site http://executeautomation.com/demosite/Login.html as shown below Here is the complete video discussed about the Hover and hover click operation, Here is the code snippet Hover
public static void Hover(WebDriver driver, WebElement element) {
	Actions action = new Actions(driver);
	action.moveToElement(element).perform();
}
Hover and Click
public static void HoverAndClick(WebDriver driver,WebElement elementToHover,WebElement elementToClick) {
	Actions action = new Actions(driver);
	action.moveToElement(elementToHover).click(elementToClick).build().perform();
}
Thanks for watching the video and reading the post !!! Please leave your comments and let me know if there is anything needed to be improved in this post. Thanks, Karthik KK