Selenium moving the mouse over an element

Problem : ‘Hover’ functionality failing in smaller screens

Real Problem : MoveToElement(element).Click().Build().Perform() works only when the element is visible in the screen.

Easy Solution is move to scroll down/up to view that element, then click. Please find below, the complete code for Hover functionality including the scrollIntoView.


public static void Hover(this IWebElement element, string desc = null) {
            var executor = (IJavaScriptExecutor)DriverBase.Driver;
            executor.ExecuteScript("arguments[0].scrollIntoView(true);", element);

            var actions = new Actions(DriverBase.Driver);
            actions.MoveToElement(element).Click().Build().Perform();

        }

Leave a Comment

Your email address will not be published. Required fields are marked *