Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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(); 
like image 423
Rahul Lodha Avatar asked Dec 03 '13 15:12

Rahul Lodha


People also ask

How do I use mouseover in Selenium?

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.

Which of the following performs mouse over function in Selenium Webdriver?

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.

How do you click on an element which is hidden using Selenium Webdriver?

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.

How do you hover over and click on an invisible element using Selenium Webdriver in Python?

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.


1 Answers

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(); 
like image 87
ton.yeung Avatar answered Sep 17 '22 13:09

ton.yeung