Suppose you want to test that when you hover over an element, a drop list is displayed. You may want to check the contents of this list, or perhaps select an option from the list.
First create an Action, to hover over the element (e.g. my element has link text "Admin"):
Actions mouseHover = new Actions(driver);
mouseHover.MoveToElement(driver.FindElement(By.LinkText("Admin"))).Perform();
In the example above:
mouseHover
driver
to move to a specific elementActions
with the mouseHover
object or continue testing with your driver
objectThis approach is of particular use when clicking on an element performs a different function than hovering over it.
A full example:
Actions mouseHover = new Actions(driver);
mouseHover.MoveToElement(driver.FindElement(By.LinkText("Admin"))).Perform();
Assert.IsTrue(driver.FindElement(By.LinkText("Edit Record")).Displayed);
Assert.IsTrue(driver.FindElement(By.LinkText("Delete Record")).Displayed);