Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 悬停一秒后消失_C#_.net_Internet Explorer_Selenium_Selenium Webdriver - Fatal编程技术网

C# 悬停一秒后消失

C# 悬停一秒后消失,c#,.net,internet-explorer,selenium,selenium-webdriver,C#,.net,Internet Explorer,Selenium,Selenium Webdriver,你好 我试图将鼠标悬停在网站菜单上,然后单击其内部链接(仅在鼠标悬停其可见后) 但问题是,当我在菜单上停留时,它只会出现一秒钟,它发生在InternetExplorerWebDriver上,在其他网站上,一切正常 可能是什么 我的尝试: Actions actions = new Actions(driver); IWebElement menuHoverLink = driver.FindElement(By.XPath("//div[@id='Menu']/ul/li[2]")); acti

你好

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

但问题是,当我在菜单上停留时,它只会出现一秒钟,它发生在InternetExplorerWebDriver上,在其他网站上,一切正常 可能是什么

我的尝试:

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
  • 单击menu
    driver.FindElement(By.XPath(“//div[@id='menu']]/ul/li[2]”)。单击()例外:元素不可单击。
我的代码是:

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
Actions动作=新动作(驱动程序);
IWebElement menuHyperLink=driver.FindElement(By.XPath(“//div[@id='Menu']]/ul/li[2]”);
actions.MoveToElement(菜单链接);

actions.Build().Perform();// 看起来这是InternetExplorerDriver的一个已知问题

按照

悬停在元素上

当您尝试将鼠标悬停在元素上时,请使用物理鼠标 光标位于IE浏览器窗口(悬停)的边界内 这是行不通的。更具体地说,悬停将在一段时间内有效 几分之一秒,然后该元素将恢复到原来的状态 以前的状态。为什么会发生这种情况的流行理论是IE是 在事件循环期间执行某种类型的命中测试,这会导致 当物理光标移动时响应物理鼠标位置 在窗口范围内。WebDriver开发团队已经 无法找到IE此行为的解决方法

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

希望这有帮助。

试试这个:-

String javaScript = "var evObj = document.createEvent('MouseEvents');" +
                    "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" +
                    "arguments[0].dispatchEvent(evObj);";


((JavascriptExecutor)driver).executeScript(javaScript, webElement);

为什么不试试
actions.MoveToElement(菜单链接)。单击().Build().Perform()仍然相同,出现一秒钟…可能是鼠标悬停时出现的菜单在单击后关闭?您可以尝试注释行
操作。单击()
,并让我们知道它是否适合您…我尝试了所有选项,包括或不包括,单击,构建,以所有组合执行。。什么都不起作用,它看起来像是在鼠标悬停后页面被重新加载或是其他什么…你是否尝试过手动操作,鼠标悬停保留了多长时间?