首页 > 解决方案 > Selenium 悬停代码适用于 Chrome 而不是 Edge

问题描述

public void Hover()
{
    Actions action = new Actions(BrowserWindow.Instance.Driver);
    action.MoveToElement(WebElement).Perform();
}

这在 Chrome 中有效。不是边缘。我已与开发人员确认我“悬停”在正确的元素上。

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);

这也失败了。有人知道我做错了什么吗?

更多信息。

这在 Firefox 上也失败了。我看到一篇关于过时的硒驱动程序的文章。我刚刚安装了 geckodriver 并将 Edge 驱动程序设置为根据文档自动更新。我不相信我有过时的驱动程序。

更多信息采取 2

调用代码是

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();
}

如果我在按钮关闭处设置断点......在悬停尝试之后,我注意到将鼠标移到“选项卡”上也不会导致按钮可见。

标签: javaseleniumselenium-webdriverwebdriveraction

解决方案


这很奇怪。但是更换

action.MoveToElement(WebElement).Perform();

action.MoveToElement(WebElement).Build().Perform();

它有效。我读到Build内置于Perform中。但我有点只是在拍它,希望有什么东西掉出来。它奏效了。


推荐阅读