I'm at my wits end here. I'm assuming I'm doing something wrong but I cannot for the life of me figure out what.
I have a navbar I'm trying to hover over the main element, which causes the drop down to expand, and then click on a child element in IEx86. This seems simple, right?
HTML (generic-ed up):
<nav class="navHeader">
<ul class="topNavigation">
<li class="firstItem"><a href="/Home">Home</a></li>
<li class="current"><a href="javascript:void(0)">Transactions</a>
<ul style="display: block;">
<li class=""><a class="tabbedTransactions" href="/Transaction/#li1">li1</a></li>
<li class=""><a class="tabbedTransactions" href="/Transaction/#li2">li2</a></li>
<li class=""><a class="tabbedTransactions" href="/Transaction/#li3">li3</a></li>
<li class=""><a class="tabbedTransactions" href="/Transaction/#li4">li4</a></li>
<li class=""><a class="tabbedTransactions" href="/Transaction/#li5">li5</a></li>
<li class="current bottomSubNav"><a href="/li6/" class="current bottomSubNav">li6</a></li>
</ul>
</li>
</ul>
</nav>
What I thought would work (and does if I hover my ACTUAL cursor over the Transaction element while the code is running) (WebElements are all found via xpath and passed in, xpath has been verified using a plugin) (driver is WebDriver and a public part of the class)
public void HoverClick(WebElement hover, WebElement click)
{
Actions actions = new Actions(driver);
actions.moveToElement(hover).click(click).build().perform();
}
The .moveToElement does not appear to move to so therefore there can be no click. (not even a flicker of the navBar item expanding)
public void HoverClick(WebElement hover, WebElement click)
{
Actions actions = new Actions(driver);
actions.moveToElement(hover).build().perform();
actions.click(click).build().perform();
}
With this one, moveToElement moves to (the navBar expands) but .click(click)
fails. Leaving off the .perform()
of the moveToElement
causes no change in behavior.
public void HoverClick(WebElement hover, WebElement click)
{
Actions actions = new Actions(driver);
actions.moveToElement(hover).build().perform();
actions.pause(Duration.ofMillis(1000)).build().perform();
actions.click(click).build().perform();
}
With this one, the first time the .pause()
is .build().perform()
-ed there IS a pause. The 2nd time (with .click().build().perform()
) there is no pause.
I don't know what to do from here. As stated, if I hover my actual mouse of the nav element then the code executes just fine. Please help?