Selenium WebDriver: 2.35. FireFox: 25.0
I want to move the mouse over a div which will causes a hidden image to become visible, then click the image. I have read the posts here, here, here and others. The general answer is to do something of the form:
action.moveToElement(we).moveToElement(webdriver.findElement(By.xpath("/expression-here")).click().build().perform();
However, this doesn't work in the example below:
html:
<div id="bb_testDiv">
<img class="bb_matchImgTest bb_standardHidden" src='@Url.Content( "~/images/match.png" )' alt='Match'/>
</div>
Javascript/jquery:
$( document ).on( 'hover', '#bb_testDiv', function ()
{
$( this ).find( '.bb_matchImgTest' ).toggleClass( 'bb_standardHidden' );
} )
$( document ).on( 'click', '.bb_matchImgTest', function ()
{
alert('here');
} )
CSS:
.bb_standardHidden
{
visibility:hidden;
}
C# test code:
IWebElement testDiv = WebDriver.FindElement( By.Id( "bb_testDiv" ) );
Actions builder = new Actions( WebDriver );
Actions hoverClick = builder.MoveToElement( testDiv ).MoveToElement( testDiv.FindElement( By.ClassName( "bb_matchImgTest" ) ) ).Click();
hoverClick.Build().Perform();
The problem is that the click event is not fired. Also, the element is left visible, so any subsequent mouseover hides it. Of course, this all works fine with manual testing.
The problem seems to be with the hover event. If I break this into two events - mouseenter and mouseleave (instead of hover) with addClass and removeClass (instead of toggleClass) then it works. Just wondering if it is possible to get this working with hover?