This is a simple but convenient method with a javascript call that will throw a mouseout () event depending on which one you specify (I prefer to pass them using By, but you can change this to whatever you like.
I had a problem with Chrome where the tooltips refused to close once, and then closed the other click events, causing them to fail. This method saved the day in this case. Hope this helps someone else!
public void javascript_mouseout(By by) throws Exception { for (int i=0; i<10; i++) { try { JavascriptExecutor js = (JavascriptExecutor)driver; WebElement element = driver.findElement(by); js.executeScript("$(arguments[0]).mouseout();", element); return; } catch (StaleElementReferenceException e) {
You can call it after any type of click () event, for example:
By by_analysesButton = By.cssSelector("[data-section='Analyses']"); javascript_mouseout(by_analysesButton);
Fyi, mine is trying 10x through a for loop with try / catch, because our application tends to chrome outdated elements with Chrome, so if you don't have this problem, the method will be significantly reduced.
source share