我无法获取下拉菜单中的子菜单项,因为子菜单仅在主菜单项的mouseOver事件中可见。
我的代码:
主菜单项 上的 mouseOver事件
当我尝试获取菜单的子菜单项时,我收到以下错误:“... OpenQA.Selenium.ElementNotVisibleException:无法点击元素 ”。 你建议我做什么? IWebElement element = WebDriver.FindElement(By.Id(elementID));
Actions action = new Actions(WebDriver);
action.MoveToElement(element).Build().Perform();
答案 0 :(得分:0)
我进行了Google搜索,找到了一篇文章 SELENIUM WEBDRIVER - 如何点击隐藏链接或菜单,解决了我的问题。
Here's the article.
使用 .mouseover()方法:
js.ExecuteScript("return $(\"a:contains('Fruits')\").mouseover();"); // Mouse hove to main menu
webDriver.FindElement(By.LinkText("Banana")).Click();
或使用 .hover()方法:
((JavascriptExecutor)driver).executeScript("$('div#Fruits').hover();");
webDriver.FindElement(By.LinkText("Banana")).Click();
或使用 .mouseenter()方法:
((JavascriptExecutor)driver).executeScript("$('div#Fruits').mouseenter();")
webDriver.FindElement(By.LinkText("Banana")).Click();