How to do a mouse over using selenium webdriver to see the hidden menu without performing any mouse clicks?

Rahul Lodha picture Rahul Lodha · Dec 3, 2013 · Viewed 49.7k times · Source

How to do a mouse hover/over using selenium webdriver to see the hidden menu without performing any mouse clicks?

There is a hidden menu on website which i am testing that only appears on mouse hover/over. Note: if any clicks is performed, page is redirected so please suggest a solution without click

I tried:

IWebDriver driver = new FirefoxDriver()
Actions builder = new Actions(driver)
builder.MoveToElement(driver.FindElement(By.Id("Content_AdvertiserMenu1_LeadsBtn")))
       .Click().Build().Perform();

Answer

ton.yeung picture ton.yeung · Dec 3, 2013

Try this?

// this makes sure the element is visible before you try to do anything
// for slow loading pages
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var element = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(elementId)));

Actions action  = new Actions(driver);
action.MoveToElement(element).Perform();