There is an invisible element on my HTML page which becomes visible when a mouse hover is done on the element. What I Have to do is
You could try this:
It's because of element's id is changing when you hover over it and you should find it again.
Actions builder = new Actions(driver);
WebElement mainMenuBTN = getWebEl("xpath_string",5);
builder.moveToElement(mainMenuBTN).perform();
mainMenuBTN = getWebEl("xpath_string",5);
builder.click(mainMenuBTN);
I use this method to ipmlement controlled explicit wait into my elements' instantiation.
protected WebElement getWebEl(String xpath, int waitSeconds) {
wait = new WebDriverWait(driver, waitSeconds);
return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
}