c# - 悬停一秒后消失

标签 c# .net internet-explorer selenium selenium-webdriver

你好

我试图将鼠标悬停在网站菜单上并单击它的内部链接(仅在悬停可见后)

但问题是当我将鼠标悬停在菜单上时它只显示一秒钟,它发生在 Internet Explorer WebDriver 中,在其他站点中一切正常 它会是什么?

我尝试了什么:

  • 点击菜单 driver.FindElement(By.XPath("//div[@id='Menu']/ul/li[2]")).Click();//异常:元素不可点击。

我的代码是:

Actions actions = new Actions(driver);
IWebElement menuHoverLink = driver.FindElement(By.XPath("//div[@id='Menu']/ul/li[2]"));
actions.MoveToElement(menuHoverLink);
actions.Build().Perform(); // <- appear for a sec and closed
actions.Click(); // <- doing nothing 

driver.FindElement(By.Id("inMenuLink")).Click(); // Exception: element not visible

最佳答案

看起来这是 InternetExplorerDriver 的一个已知问题。

根据 official documentation of InternetExplorerDriver

Hovering Over Elements

When you attempt to hover over elements, and your physical mouse cursor is within the boundaries of the IE browser window, the hover will not work. More specifically, the hover will appear to work for a fraction of a second, and then the element will revert back to its previous state. The prevailing theory why this occurs is that IE is doing hit-testing of some sort during its event loop, which causes it to respond to the physical mouse position when the physical cursor is within the window bounds. The WebDriver development team has been unable to discover a workaround for this behavior of IE.

如上一期所述,您应该尝试将您的物理鼠标光标移出 IE 窗口边界,然后尝试执行您的代码。

希望这对您有所帮助。

关于c# - 悬停一秒后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34588639/

相关文章:

html - 为什么这个网站在 IE 8 中完全崩溃,但在 Firefox 3.6.2 中却能完美运行?

c# - C# 中多次转换的规则是什么?

c# - 我怎样才能阅读这个 XML 部分?

c# - 使用程序集中的 Web 应用程序版本号 (ASP.NET/C#)

.net - 如何创建 Type 类型的依赖属性,并在 XAML 中分配它?

javascript - 如何阻止 IE8 或更低版本访问某个网站?

jquery 数据表修复了在 IE 中不对齐的列

c# - 具有不同数据类型的主要方法

c# - 将对象添加到 LINQ 中的字典值?

.net - 那么 [Email] 属性是否内置于 ASP.NET MVC 3 中?