你好
我试图将鼠标悬停在网站菜单上并单击它的内部链接(仅在悬停可见后)
但问题是当我将鼠标悬停在菜单上时它只显示一秒钟,它发生在 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/