Reputation: 81
public void Hover()
{
Actions action = new Actions(BrowserWindow.Instance.Driver);
action.MoveToElement(WebElement).Perform();
}
This is working in Chrome. Not Edge. I have confirmed with the developer that I am "hovering" over the correct element.
WebElement elem = yourWebDriverInstance.findElement(By.xpath("//*[@class='goog-menu goog-menu-vertical uploadmenu density-tiny']/input"));
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
((JavascriptExecutor) yourWebDriverInstance).executeScript(js, elem);
Which also failed to work. Anyone have any idea what I am doing wrong?
More info.
This is also failing on Firefox. I saw an article about out of date selenium drivers. I have JUST installed both geckodriver and set the Edge driver to auto update according to the documentation. I do not believe I have out of date drivers.
More info take 2
Calling code is
public static void DoCloseActiveTabEntire()
{
Element tab = new Element(byTab);
tab.Hover();
// CLose button is not clickable. Cannot use standard BUTTON for find
Button close = new Button(byClosePanelButton);
close.Click();
}
If I set a break point at button close... after the hover attempt, I notice that moving my mouse over the "tab" also does not cause the button to be visible.
Upvotes: 0
Views: 901
Reputation: 81
So, I don't know why I thought the build().perform() did the job. I know it worked ONCE. What I wound up doing is keeping the hover code the same.
public void Hover()
{
Actions action = new Actions(BrowserWindow.Instance.Driver);
action.MoveToElement(WebElement).Build().Perform();
Thread.Sleep(1000);
}
I changed the calling code which attempts to close the panel/page whatever I want to call it to this:
public static void DoCloseActiveTabEntire()
{
// So there is a defect in EDGE whereby the behavior of the code containted in the hover on the tab executes without
// error but the action underneath does not occur. So in Edge, callng the hover method of the TAB as seen in the else condition
// below does nto display the CLOSE button which needs to be clicked.
// So for Edge, javascript is used to display the button directly.
IWebElement close;
if (BrowserWindow.Instance.Browser == BrowserWindow.Browsers.Edge)
{
close = BrowserWindow.Instance.Driver.FindElement(byClosePanelButton);
string js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible'; arguments[0].style.display='inline';";
IWebDriver driver = BrowserWindow.Instance.Driver;
IWebElement element = close;
((IJavaScriptExecutor)driver).ExecuteScript(js, element);
}
else
{
Element tab = new Element(byTab);
tab.Hover();
close = new Button(byClosePanelButton).WebElement;
}
close.Click();
}
For me, I am happy that the thing can be closed. I don't care that much whether the hover achieves it.
Upvotes: 0
Reputation: 81
This is weird. But replace
action.MoveToElement(WebElement).Perform();
with
action.MoveToElement(WebElement).Build().Perform();
And it works. I read that the Build is built into Perform. But I was kinda just smacking at it hoping something fell out. And it worked.
Upvotes: 1
Reputation: 193308
perform()
perform() is the convenience method for performing the actions without calling build()
first.
build()
build() generates a composite action containing all actions so far, ready to be performed and additionally also resets the internal builder state, so subsequent calls to build()
will contain fresh sequences.
In your usecase, you have invovoked perform()
just after moveToElement(WebElement)
without generating the composite action to be performed using build()
.
A straight forward solution would be to invoke build()
before perform()
as follows:
public void Hover()
{
Actions action = new Actions(BrowserWindow.Instance.Driver);
action.moveToElement(WebElement).build().perform();
}
Upvotes: 0