Maybe somebody can help me figure this out. I want to be able to create a chain of Actions using java and Selenium webdriver. Here is what the source of the webpage looks like:
<li id="menu-item-14" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-5 current_page_item menu-item-has-children menu-item-14"><a href="http://www.somewebsite.com/about/">About</a>
<ul class="sub-menu" style="display: none; visibility: hidden;">
<li id="menu-item-43" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-43"><a href="http://www.somewebsite.com/team/">Team</a></li>
</ul>
</li>
Basically when you hover over the About menu a submenu name Team will appear and I want to be able to select the submenu. This is what my code looks like
WebElement aboutMenu = _driver.findElement(By.id("menu-item-14"));
Actions builder = new Actions(_driver);
Action seriesofactions = builder
.moveToElement(aboutMenu)
.moveToElement(_driver.findElement(By.id("menu-item-43")))
.click()
.build();
seriesofactions.perform();
If I take the second moveToElement the code works just fine. Any ideas will be appreciated?
Update: Java Code used
WebElement menuHoverLink = _driver.findElement(By.id("menu-item-14"));
actions.moveToElement(menuHoverLink).perform();
try {
((JavascriptExecutor) _driver).executeScript("document.getElementByid('menu-item-14')).style.display='block'");
} catch (Exception e) {
e.printStackTrace();
}
_driver.findElement(By.id("menu-item-43")).click();