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
Well, after going through your questions numerous times and changing my answers many times I will go with -
Issue - what I got from the original code -
You need to move the cursor to the mainMenuBTN (which is visible not the element that becomes visible when you hover the mouse over it ) and subMenuBTN is then displayed which you need to click.
The only edit to your original code as per me will be adding a statement to move the cursor to your subMenuBTN before you click it. This way works fine for me when I need to click sub menu item.
Actions builder = new Actions(driver);
builder.moveToElement(mainMenuBTN).build().perform();
builder.moveToElement(subMenuBTN).build().perform();
subMenuBTN.click();
Please let me know if this is the case.