How to MouseOver in your C# tests

I have created a fairly simple to use C# method to perform a MouseOver operation, all you need to do is to specify the web element to MouseOver.

Add the following using statement first:

using OpenQA.Selenium.Interactions;

Then create the following method:

public static void MouseOver(IWebElement theElement)
{
	Actions builder = new Actions(driver);
	builder.MoveToElement(theElement).Build().Perform();
	Thread.Sleep(1500);
}

Its fairly easy to use and I have a sample of how to call it below:

IWebElement theMenuLink = driver.FindElement(By.Id("menu"));
MouseOver(theMenuLink);

Leave a Comment