Wednesday 30 May 2018

IE mouse hover on drop down

Mouse hovering works like butter on chrome and firefox but when it comes to IE it doesn't. I faced issue with navigating multiple sub menu's (here 2 level depth). Issue was I mouse hover on main menu which displays sub menu and again hover on it which displays another one and then click one of them based on a condition.

What I tried:
1. With Action Class -> nested hovering (moveToElement().moveToElement()) -> No luck
2. With Action Class -> partial hovering (moveToElement()) next command click -> Intermittent success
3. Thread pool -> 2 separate threads one listening for sub menu visibility and another clicks on menu ->  Intermittent success

What Finally Worked:
 String hover= "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover',true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
         ((JavascriptExecutor) getDriver()).executeScript(hover,getDriver().findElement(By.xpath("")));
         ((JavascriptExecutor) getDriver()).executeScript(hover,getDriver().findElement(By.xpath("")));