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();
The first step here would be to locate the main menu (AKA parent menu). Once that is done, the second step is to locate the desired element (child element) from the available options in the sub-menu. The final step would be to click on that child element.
We can perform mouseover action on elements in Selenium with the help of Actions class. In order to perform the mouse movement we will use moveToElement () method of the Actions class. Finally use build(). perform() to execute all the steps.
In case an element is a part of the form tag, it can be hidden by setting the attribute type to the value hidden. Selenium by default cannot handle hidden elements and throws ElementNotVisibleException while working with them. Javascript Executor is used to handle hidden elements on the page.
You need to move the cursor to the mainMenuBTN (which is visible not the element that becomes visible when you hover the mouse over it ) and subMenuBTN is then displayed which you need to click.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With