23

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();
PUG
  • 4,301
  • 13
  • 73
  • 115
Rahul Lodha
  • 3,601
  • 7
  • 25
  • 34

5 Answers5

48

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();
ton.yeung
  • 4,793
  • 6
  • 41
  • 72
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");
Ajay
  • 395
  • 1
  • 4
  • 11
2

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

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

David
  • 3,223
  • 3
  • 29
  • 41
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:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352