3

Selenium Webdriver 2.31.0 with Scala 2.9

Anyone know how to do a mouse hover in Firefox? I'm basically trying to hover over an element to display a tooltip.

This code fails to move the mouse over the element specified.

      val webElement = webDriver.findElement(By.cssSelector(myElement.queryString))
      val builder = new Actions(webDriver)
      val hover = builder.moveToElement(webElement).build()
      hover.perform()

I have also tried mouse events without success (as described here WebDriver mouseOver is not working properly with selenium grid)

Community
  • 1
  • 1
user786045
  • 2,498
  • 4
  • 22
  • 18
  • 1
    Are you getting any error message? – Dingredient Jun 11 '13 at 16:25
  • I am also getting same problem the thing is that when I run mouse over code(same code as above) the mouse over appears and then remove. Anyone please help me to find out this. I am using latest chrome browser. – kailash gaur Jul 15 '14 at 06:11

3 Answers3

2

This is somewhat anecdotal since I don't have an exact technical explanation, but I've experienced this in the past and have remedied by upgrading Selenium.

The first thing I check is to make sure my selenium is up to date. This includes dependencies, standalone-server and browser drivers (though, in this case, not applicable as Firefox is included with Selenium).

Another possible (and more probable) cause, more directly related to Firefox, is Firefox itself. It's been my experience that a Firefox update can, from time to time, break some selenium functions, particularly hovers. I've found that either upgrading selenium, or if no update has been released, downgrading Firefox will solve the problem.

I wish I had more detailed information to give you, but I'm still learning the finer details of this situation myself. If nothing else, I hope this points you in the right direction.

tim-slifer
  • 1,068
  • 1
  • 9
  • 17
1

Since you havn't said you got any errors,

  • After build().perform(), provide a wait method say, Thread.sleep() for certain amount of time, since there are posibilities where mousehover performed in fraction of seconds and it may not be possible to see the tooltip.

  • Makesure the locator is correct (because you may point to someother locator which doesn't show up any tooltip)

  • Makesure you firefox supports the mousehover functionality

The code might resemble as same as your's, but give it a try(JAVA),

        Actions builder = new Actions(driver); 

        WebElement we = driver.findElement(locator);

        Actions perf= builder.moveToElement(we).build();

        perf.perform();

        Thread.sleep(1000);

You can look out the link for your ref : #firefox issue

Community
  • 1
  • 1
Vignesh Paramasivam
  • 2,360
  • 5
  • 26
  • 57
1

As your issue is in Firefox, you may need to enable Native Events with webdriver, specifically

FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);

I've had to do this to get drag and drop working in Firefox on Unix, although it worked with the same code on a Windows box.

Ross Taylor-Turner
  • 3,687
  • 2
  • 24
  • 33