How to mouseover on a hyperlink - Webdriver How to mouseover on a hyperlink - Webdriver selenium selenium

How to mouseover on a hyperlink - Webdriver


I had the same issue and solved it by moving the cursor by 1px. The last line triggered the hover event.

Actions action = new Actions(driver);action.moveToElement(element).build().perform();action.moveByOffset(1, 1).build().perform();


Try this:

Actions action = new Actions(webdriver);WebElement we = webdriver.findElement(By.xpath("x_p_a_t_h"));action.moveToElement(we).build().perform();


I've used the public void mouseOver(String) method in the DefaultSelenium class. The essence of the code is as follow:

protected void hoverAction() {    WebDriverBackedSelenium webDriver = some_elaborate_method_to_get_webdriver;    webDriver.mouseOver("x_p_a_t_h");}

You may also need to look into putting some sort of wait time on your hover to ensure the element gets rendered before you fail (eg. fly out menus, typically launched from links don't appear instantly).