1

I don't know what to do with this mouseOver in selenium. I'm working with FF13. And with the last version of webdriver.

I read this Is there a proved mouseOver workaround for FirefoxDriver in Selenium2? and i did exactly like this:

Actions builder = new Actions(driver); Actions hoverOverRegistrar = builder.moveToElement(menuRegistrar); hoverOverRegistrar.perform();

but when it points to the object an other object (dropdown menu) appears just for a moment and then hides, so selenium not always has time to click on appeared dropdown menu.

What am i doing wrong?

Community
  • 1
  • 1
Oleg Strokatyy
  • 631
  • 2
  • 10
  • 23

2 Answers2

3

Hoverable elements I find it's best to use JavaScript. Action Builder tends to have a high rate of failure, and will cause other hoverable elements to become visible as it scrolls through the page, causing the element that you want to become obscured. I've found this method somewhere online (can't remember where) and it works significantly better than any other method I've tried.

String javaScript = "var evObj = document.createEvent('MouseEvents');" +
                "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" +
            "arguments[0].dispatchEvent(evObj);";


IJavaScriptExecutor executor = driver as IJavaScriptExecutor;
executor.ExecuteScript(javaScript, webElement);

Just throw it in a method in a place where you can use it, pass it the driver and element you want to hover over and you'll be set.

  • This worked well Dominic, thank you, I'm able to use the JavaScript snippet you provided. After hovering, if one wants to clear the hovering, refreshing browser is one option other than clicking another element. Is there any other option? I used: driver.Navigate().Refresh(); – Sohel Sep 10 '18 at 22:46
2

I guess some thing like this should work -

Actions builder = new Actions(driver);
builder.moveToElement(DropDown tab element).click().moveToElement(Tab you want to click element).click().build().perform();

If there is any problem.Please post the stack trace you get.

Hari Reddy
  • 3,808
  • 4
  • 33
  • 42
  • This works: Actions builder = new Actions(driver); builder.moveToElement(DropDown tab element).moveToElement(Tab you want to click element).click().build().perform(); – Oleg Strokatyy Jul 17 '12 at 21:03
  • but i thought there is exists some elegance solution. I thought my code will looks like that: MyFirstElement.MouseOver(); MySecondElement.Click(); But now it's looks like MyFirstElement.MouseOver(MySecondElement); Well... it is better than nothing. Thank you. – Oleg Strokatyy Jul 17 '12 at 21:09