How to Hover over and click on an invisible element using selenium webdriver?

java, selenium-webdriver

Solution

using javascript executor like

((JavascriptExecutor) webdriver).executeScript("document.getElementById('btn').click();");

Problem

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 - Hover over the element - Click on the element (it will display 4 options) - Click on one of the options I am using Java API for selenium web driver and following is what I have been trying ``` Actions builder = new Actions(driver); builder.moveToElement(MainMenuBTN).click().build().perform(); subMenuBTN.click(); ``` - MainMenuBTN = element that becomes visible when you hover the mouse over it - subMenuBTN = element that is being chosen out of the menu options that are displayed What is happening is, the click() on MainMenuBTN is generating ElementNotVisible exception. I tried following to avoid this, but did not work. ``` Actions builder = new Actions(driver); builder.moveToElement(mainMenuBTN).build().perform(); builder.click(); subMenuBTN.click(); ``` A Note : mainMenuBTN and subMenuBTN are WebElements generated by ``` driver.findElement(By.xpath("xpath_string")) ``` Am I missing anything? Help appreciated !

Original source