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();
When you hover over your menu-item-14, the style on the ul class="sub-menu" will change to style="display:block; and possibly remove the visibility from the styled element. That then allows the menu-item-43 to appear for selection.
See this post for more information on using mouse over hovers in selenium.
How to do mouse hover using Selenium WebDriver in Firefox 19?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.