24

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();

5 Answers 5

49

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();
Sign up to request clarification or add additional context in comments.

3 Comments

Woah! I never knew about using that TimeSpan class. Thanks!
However, it still opens another browser widow at the end
I don't understand what you mean by that
2

yeah the question you posted is about tool tip

perform mouse hover the then capture its attribute value

closely observe your HTML code manually move your mouse pointer on the element & observe in which attribute value your hidden text present

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


String value=driver.FindElement(By.Id("Content_AdvertiserMenu1_LeadsBtn")).getAttribute("attribute value in which hidden text presents");

Comments

2

You need to use - using OpenQA.Selenium.Interactions;

Comments

1

Just wanted to mention that a last resort workaround could be to try javascript mouse over simulation.

Solutions for that in various languages are posted here: http://code.google.com/p/selenium/issues/detail?id=2067

Comments

0

To do a Mouse Hover using Selenium webdriver to see the hidden menu without performing any mouse clicks you need to ensure that the desired ElementIsVisible() inducing WebDriverWait and the use Actions Class methods as follows:

using OpenQA.Selenium.Interactions;

var element = new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementIsVisible(By.Id("elementID")));
new Actions(driver).MoveToElement(element).Perform();

In a single line:

new Actions(driver).MoveToElement(new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementIsVisible(By.Id("elementID")))).Perform();

References

You can find a couple of relevant detailed discussions in:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.